Answer the question
In order to leave comments, you need to log in
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
See also the joinWith solution - it helps solve some of these problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question