Reputation: 217
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