Answer the question
In order to leave comments, you need to log in
How to filter by the number of related models?
There is an Author model with a hasMany posts relationship configured. By condition, I get an array of Author models along with posts. How at the ORM level not to include those Authors whose number of posts is zero?
Answer the question
In order to leave comments, you need to log in
use joinWith
like:
Author::find()->joinWith( 'posts', true, 'INNER JOIN' )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question