- Things to know before using ORM
- How field attributes work
- Set property type
- Set table field type
- Set table field length
- Set table field default value
- Define property field as primary field
- Set relation
- Set enumeration
- Implement custom value type
- Map property to custom field name
- Set null
- Set unsigned
- Set zerofill
- Set date on insert on update
Load by field equals value or field is like value
To load object by custom field value:
$database->path->to->class->load (\db\by(string $field1, mixed $value1)->by(string $field2, mixed $value2)->in(string $field3, mixed $value));
\db\by and \db\in create instance of \db\by class which has to methods \db\by:by and \db\by::in each method returns instance of itself therefore you can add another criteria by calling again method 'in' or method 'by'. Table handler than generates a query with cross criterias with 'AND'.
Will generate query something like this:
... where login='administrator' and password='1234' and group like '%|1|%'
'in' method generates 'like' statement for enumerated fields which in db.php are stored like '|value1|value2|value3|'. Enumerated fields are subject of further reading and we will not describe it here in details.
value parameter can also be objects or boolean values except of regular strings:
$group = $database->user->group->load (1); $database->user->user->load (\db\by('group',$group)->by('active',true));
Each string is escaped and protected from injection.
Dont get confused because of \db\ prefix in \db\by function call followed by simply ->by in \db\by()->by. \db\ is namespace prefix and it is necessary because by function resides in db namespace.