P
P
Pavel Ivanov2016-12-07 09:00:16
Yii
Pavel Ivanov, 2016-12-07 09:00:16

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

1 answer(s)
M
Maxim Fedorov, 2016-12-07
@eastywest

use joinWith
like:

Author::find()->joinWith( 'posts', true, 'INNER JOIN' )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question