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

help pls count relation #430

Closed
hotlabs opened this issue Aug 9, 2020 · 1 comment
Closed

help pls count relation #430

hotlabs opened this issue Aug 9, 2020 · 1 comment

Comments

@hotlabs
Copy link

hotlabs commented Aug 9, 2020

im have model - Model_Category
and relation $_many_many = array('posts')

how can i get lists categoryes and get count relation
like:
category (100posts)
category2 (300posts)
category3 (600posts)

$cats= Model_Category::query()->get();
foreach($cats as $cat){
echo $cat->name . ' ' . count($cat->posts);
}
-> this method not good
im need only count - and not full posts lists
because there are a lot of posts

@WanWizard
Copy link
Member

The ORM is not a query builder, so don't use it as such. Instead, use the query builder, DB, to construct the query.

p.s. for user questions, please use the forum, the issue tracker is for issues.

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