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

3.0 counter cache error with lambda counters #4846

Merged
merged 2 commits into from
Oct 10, 2014

Conversation

dakota
Copy link
Member

@dakota dakota commented Oct 9, 2014

When using counterCache with a lambda counter, it would error if the entity foreign_key is updated as it was calling _getCount() with the lambda (and _getCount expects an array)

I added in a $original argument to the counterCache callable to determine what part of the count is being called.

@antograssiot
Copy link
Contributor

Do we really need to add the boolean $original to the callable ? Maybe we can just return the count pending on the $entity->getOriginal() ?

Anyway I missed that case, thank's for noticing 👍 😉

@antograssiot antograssiot added this to the 3.0.0 milestone Oct 9, 2014
@dakota
Copy link
Member Author

dakota commented Oct 9, 2014

The callable is being called twice (Once to update the new foreign_key, and second to update the original foreign_key). I don't think there is another way to determining which time is being called without adding a new argument?

@antograssiot
Copy link
Contributor

Forgot my comment. I though we could check if it's an update by checking differences between $entity->getOriginal('foo') and $entity->get('foo') inside the callable. Doesn't seems to work as you do several save.

@markstory
Copy link
Member

Looks good to me.

@dakota
Copy link
Member Author

dakota commented Oct 10, 2014

@antograssiot - I think that might actually work since the Entity object itself is not actually saved. Will quickly give it a test.

@dakota
Copy link
Member Author

dakota commented Oct 10, 2014

@antograssiot Sorry, it obviously won't work. get('foo') and getOriginal('foo') will always be different if foo has been changed.

@antograssiot
Copy link
Contributor

@dakota Yeah I know I give it a try yesterday and couldn't find a working way. Sorry if I made you waste some time by not beeing clear about previously digging into this

it's good to merge to me, thank's again 👍

@dakota
Copy link
Member Author

dakota commented Oct 10, 2014

No worries, was a quick check :)

markstory added a commit that referenced this pull request Oct 10, 2014
3.0 counter cache error with lambda counters
@markstory markstory merged commit 187e37c into cakephp:3.0 Oct 10, 2014
@markstory
Copy link
Member

Thanks 👍

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

Successfully merging this pull request may close these issues.

None yet

3 participants