Lithium Li3 “Inner Join”
-
02-01-2020 - |
Question
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.
Solution
Just create a normal model relationship and 'mode' => 'INNER'
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow