creality
creality

Reputation: 217

Lithium Li3 "Inner Join"

I need to do a "Inner Join" between two MySQL Tabels via the Li3 Lithium3 framework.

My model relationships are ok for "Left Joins". But I don't know how to perform an inner join to do some more filtering via sql.

Manually it works (with a custom finder):

Posts::finder ('popular', function($self, $params, $chain) {
$db = Connections::get ($self::meta ('connection'));
$records = $db->read (
"SELECT * FROM `posts` p INNER JOIN `post_metas` pm ON (pm.`post_id` = p.`id` AND pm.`meta_key`='views') ORDER BY pm.`int_value` DESC", array('return' => 'object'));
return $records;

});

But this is not really dynamic.

Does anyone know how to do this with lithium relationships?

thx in advise.

Upvotes: 2

Views: 297

Answers (1)

Nate Abele
Nate Abele

Reputation: 5770

Just create a normal model relationship and 'mode' => 'INNER'.

Upvotes: 2

Related Questions