M
M
Maxim Timofeev2015-12-01 18:42:29
Yii
Maxim Timofeev, 2015-12-01 18:42:29

How to generate a query using activerecords?

There are tables users and articles. The articles have a "user_id" by which they are linked, through hasOne and hasMany (these are the authors of the articles)
I can't figure out how to select only users who have at least one article and sort them by the number of articles. At what it is necessary to take into account only articles with status - 1.
So far I have come up with only the option to select articles, collect an array of unique "user_id" and select users by these id.
But perfectionism suggests that it can be easier.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2015-12-02
@Akdmeh

See also the joinWith solution - it helps solve some of these problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question