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

can Countable support relation or condition ? #51

Closed
gabrieltong opened this issue Apr 2, 2016 · 7 comments
Closed

can Countable support relation or condition ? #51

gabrieltong opened this issue Apr 2, 2016 · 7 comments
Assignees
Milestone

Comments

@gabrieltong
Copy link

Countable is easy to use , but It doesn't work in my case .

post has two state : active or inactive
user can has three relation to post : all post , active posts and inactive posts, 
and I want to cache all three count

thanks

@gabrieltong
Copy link
Author

I checked the code, it's not based on eloquent relation, but db sql, why do we use relation ? so there's no condition problem, I can put the condition in relation .

@kirkbushell
Copy link
Owner

The reason is because the SQL statement helps to avoid race condition issues where 2 requests may be executed at the same time, resulting in an incorrect count on the related table. If you're fetching an object, and then making a change and doing the update that way, you will get incorrect counts over time.

That said, I think we could also do an update() call against the relation, that could work. I think this deserves some more thought, thanks for the heads up!

@kirkbushell kirkbushell added this to the 2.1.0 milestone Apr 4, 2016
@kirkbushell kirkbushell self-assigned this Apr 4, 2016
@divdax
Copy link

divdax commented Aug 14, 2017

I also need to apply a condition for counting related rows. e.g. User (posts_count) - Post where active = 1.

@jaulz
Copy link

jaulz commented Mar 15, 2021

@kirkbushell is this still somewhere on the roadmap? would you accept a PR?

@kirkbushell
Copy link
Owner

@jaulz I would.

@kirkbushell kirkbushell modified the milestones: 2.1.0, 11.0 Aug 26, 2023
@kirkbushell
Copy link
Owner

@gabrieltong this is solved in #107 - if you have time/moment, would be great to test it out and just double-check. But now, Eloquence support model relationships by default and works with them to drive the behaviours of the library.

@kirkbushell
Copy link
Owner

Closing as this will be available in the next big release for Eloquence.

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

4 participants