Last updated
Last updated
Once you have an entity and its associated database table you can start retrieving data from your database.
You can configure your query to retrieve entities using any qb method. It is highly recommended you become familiar with the
You start every interaction with Quick with an instance of an entity. The easiest way to do this is using WireBox. getInstance
is available in all handlers by default. WireBox can easily be injected in to any other class you need using inject="wirebox"
.
Quick is backed by qb, a CFML Query Builder. With this in mind, think of retrieving records for your entities like interacting with qb. For example:
In addition to using for
you can utilize the each
function on arrays. For example:
You can add constraints to the query just the same as you would using qb directly:
A second way to retrieve results is to use a Quick Service. It is similar to a VirtualEntityService
from cborm.
The easiest way to create a Quick Service is to inject it using the quickService:
dsl:
Any method you can call on an entity can be called on the service. A new entity will be used for all calls to a Quick Service.
Calling qb's aggregate methods (count
, max
, etc.) will return the appropriate value instead of an entity or collection of entities.
Returns true if any entities exist with the configured query. If no entities exist, it throws an EntityNotFound exception.
Retrieves all the records for an entity. Calling all
will ignore any non-global constraints on the query.
Executes the configured query, eager loads any relations, and returns the entities in a new collection.
Executes the configured query, eager loads any relations, and returns the entities in the configured qb pagination struct.
Executes the configured query and returns the first entity found. If no entity is found, returns null
.
Adds a basic where clause to the query and returns the first result.
Executes the configured query and returns the first entity found. If no entity is found, then an EntityNotFound
exception is thrown with the given or default error message.
Finds the first matching record or returns an unloaded new entity.
Finds the first matching record or creates a new entity.
Returns the entity with the id value as the primary key. If no record is found, it returns null instead.
Returns the entity with the id value as the primary key. If no record is found, it throws an EntityNotFound
exception.
Returns the entity with the id value as the primary key. If no record is found, it returns a new unloaded entity.
Returns the entity with the id value as the primary key. If no record is found, it returns a newly created entity.
Hydration is a term to describe filling an entity with a struct of data and then marking it as loaded, without doing any database queries. For example, this might be useful when hydrating a user from session data instead of doing a query every request.
Hyrdates an entity from a struct of data. Hydrating an entity fills the entity and then marks it as loaded.
If the entity's keys are not included in the struct of data, a MissingHydrationKey
is thrown.
Hydrates a new collection of entities from an array of structs.
If you would like collections of entities to be returned as something besides an array, you can override the newCollection
method. It receives the array of entities. You can return any custom collection you desire.
Returns a new collection of the given entities. It is expected to override this method in your entity if you need to specify a different collection to return. You can also call this method with no arguments to get an empty collection.
For more information on what is possible with qb, check out the .