Assume we have models defined in Defining Models

Retrieving A Record By Primary Key

Retrieving A Record By Conditions


By the convention, the Model property name is processed by camelCase. For example, if the users table has column created_time. To get the created_time value through model, you should use: $user->createdTime

Retrieving Multiple Records AKA Collection

Retrieving Multiple Records By Primary Key List

Retrieving Multiple Records By Conditions


Almost all sql Select method is visible in Collection: select, distinct, calcFoundRows, where, orWhere, having, orHaving, orderBy, groupBy, limit, offset, join, leftJoin, rightJoin,
Sql querying in Collection is Lazy, it mean there are no query is executed until you interacting with the collection data. So you could adding more query filter to the collection later.
The Model Collection class is implemented of Countable, IteratorAggregate, JsonSerializable, ArrayAccess. So you could counting, iterate, encode as json or interacting it as array style.


comments powered by Disqus