0vote

ORM: Finding a Specific Model, Loading a "Collection"

Does the Sellvana/Fulleron ORM support finding a specific model based field values, SQL or SQL Like queries? (find me the single "Foo" model where the "serial_number" is set to '894729839022')

Does it support loading a collection or PHP array of individual models? (find me all the "Foo" models where the "state" is set to "Oregon")

If so, what's the syntax for this?

1 Answer

2votes

Loading of one model:

$model1 = ModelClass::i()->load($id);
$model2 = ModelClass::i()->load($fieldValue, 'field_name');
$model3 = ModelClass::i()->load(array('field1'=>$value1, 'field2'=>$value2));

There's also lower level loading of one model, without invoking onAfterLoad:

$model4 = ModelClass::i()->orm()->where('field', $value)->find_one();

Loading of multiple models:

$orm = ModelClass::i()->orm($alias)->where('field', $value);
$models = $orm->find_many();

// default $idField = 'id'
// if $rowFields omitted, load all selected fields, 
// if array: output only selected, if string: flat array
$modelsAssoc = $orm->find_many_assoc($idField, $rowFields);

The basic syntax of ORM API: http://j4mie.github.io/idiormandparis/
There's an extended condition format allowing for complex queries within one array variable, implemented in BDb::where.

idiorm/paris will be upgraded soon, which will convert collections into objects implementing ArrayAccess

...