Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Model relations

hello. please tell me is there any way to use Model relations to build same query "SELECT c.* FROM Category AS c LEFT JOIN Video AS v ON (v.catid=c.id) WHERE c.enable = 1 GROUP BY v.catid HAVING COUNT(v.id)>0";

category: public function initialize() { $this->hasMany('id', 'Video', 'catid'); } video: public function initialize() { $this->belongsTo("catid", "Category", "id"); }



84.5k
Accepted
answer

Conditions are automatically added to the query if they're omitted in the join conditions clause:

$phql = "SELECT c.* FROM Category AS c LEFT JOIN Video AS v WHERE c.enable = 1 GROUP BY v.cat_id HAVING COUNT(v.id)>0";