Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get count in relation table in yii2 Activerecord and sort it #6042

Closed
jafaripur opened this issue Nov 13, 2014 · 1 comment
Closed

get count in relation table in yii2 Activerecord and sort it #6042

jafaripur opened this issue Nov 13, 2014 · 1 comment

Comments

@jafaripur
Copy link
Contributor

I have two table for post and user. I want to show post count of user in users list gridview. In yii 1 I use this in model to define a relation for this purpose:

'postCount' => array(self::STAT, 'Post', 'author',
'condition' => 'status = ' . Post::ACTIVE),

...
User:find...().with('postCount').....

But i don't know how to implement this in Yii2 to get count of post in User:find():with('...') to show in gridview.
Anyone try this in yii2?

In other words, I want to show post count of each user in gridview. I have seasearchedloa lotf this question in internet but doesn't find a general answer. With Lazy loading this can be done, But performance comming down.

http://stackoverflow.com/questions/26894987/get-count-in-relation-table-in-yii2-activerecord
www.yiiframework.com/forum/index.php/topic/59278-get-count-in-relation-table-in-yii2-activerecord/

@qiangxue
Copy link
Member

Duplicate of #2179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants