I am getting data from 3 tables thanks to yii2 eager loading. But also, I need to run one COUNT() function to count number of returned rows from one table. If I run it inside select() method, my query will fail saying "Trying to get property of non-object" if I try to display result from one of the joined tables.
I want to count number of post_id in my comment table, executed by this query. ( I want to get comments along with posts that they belong too and users that made those comments, plus count number of posts ( defined by $posts array ) that have comments.
If I do it like that now I get another error : Trying to get property of a non object, most likely because my query hasn’t selected necessary fields from related tables, and I do not know how to disambiguate them.