I read through lithium\data\model\query, but I didn't see any examples of joins.
There are multiple ways to perform a join with Lithium.
join()
method (see the joins
.Connection->read()
.The other methods are reasonably well documented, so I'll give an example of passing Query objects to a finder.
$fields = array('id', 'name', 'slug');
$joins = array();
$joins[] = new Query(array(
'source' => 'client_tests',
'constraint' => array('Test.id' => 'client_tests.test_id'),
));
$conditions['client_id'] = $this->data['client_id'];
$tests = Test::all(array(
'conditions' => $conditions,
'fields' => $fields,
'joins' => $joins
));
The source
is the table that you want to join and constraint
is the join criteria. Lithium aliases the find table to the name of the model, so use that in your constraint. You can then pass the joins in to any finder along with any other parameters you want.
Note that at the time of writing, joins (and relationships) will only work with a relational database, not for things like MongoDB's DBRef.
Update: Removed links that have been link jacked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With