Queries With Spot
Finders (Mapper)
All these finders require a Mapper instance. Mappers are responsible for finding and updating individual entities.
The main finders used most are all
to return a collection of entities,
and first
or get
to return a single entity matching the conditions.
get([$primaryKey])
The get
method accepts a primary key to load a record with:
If there is no Entity\Post
with the primary key provided, boolean false
will be returned.
all()
Find all entities and return a Spot\Entity\Collection
of loaded Entity\Post
objects.
where([conditions])
Find all entities that match the given conditions and return a
Spot\Entity\Collection
of loaded Entity\Post
objects.
Spot\Query
object is returned with all queries, which means additional
conditions and other statements can be chained in any way or order you want.
The query will be lazy-executed on interation or count
, or manually by ending
the chain with a call to execute()
.
Conditional Variations
first([conditions])
Find and return a single Spot\Entity
object that matches the criteria.
Or first
can be used on a previous query with where
to fetch only the first
matching record.
A call to first
will always execute the query immediately, and return either
a single loaded entity object, or boolean false
.
select()
To get an instance of the query builder (Spot\Query
) with no conditions set
on it, use select
.
This is effectively the same thing as all()
, but without any semantics attached.