Skip to content

Conversation

@bogdan
Copy link
Contributor

@bogdan bogdan commented Sep 3, 2015

There are two methods that return the counter cache column name now in code: one for belongs_to association and one for all others. That's a little confusing. So, now they are merged.

Current implementation has a lot of utility methods that accept
reflection call a lot of methods on it and exit.

E.g. has_counter_cache?(reflection)

It Breaks OOP principle XXX from the guide book and causes confusion and inability of caching even
through it always returns the same result for the same reflection object.
It can be done easier without access to the association context
by moving code into reflection itself.

e.g. reflection.has_counter_cache?

Reflection is less complex object than association so moving code there
automatically makes it simpler to understand.

Current implementation has a lot of utility methods that accept reflection call a lot of methods on it and exit. E.g. has_counter_cache?(reflection) It causes confusion and inability to cache result of the method even through it always returns the same result for the same reflection object. It can be done easier without access to the association context by moving code into reflection itself. e.g. reflection.has_counter_cache? Reflection is less complex object than association so moving code there automatically makes it simplier to understand.
@rails-bot
Copy link

r? @eileencodes

(@rails-bot has picked a reviewer for you, use r? to override)

@eileencodes
Copy link
Member

This refactoring makes sense to me. This is a breaking change though, since you can no longer do has_counter_cache?(reflection) so there needs to be a changelog and deprecation notice for all the methods that have changed how they are used in applications.

@bogdan
Copy link
Contributor Author

bogdan commented Sep 5, 2015

@eileencodes has_counter_cache? method was removed from HasManyAssociation that has :nodoc: flag that indicates that class is private. I don't think that undocumented classes API should be maintained in rails.

@eileencodes
Copy link
Member

Ah yes ok - I didn't see it on the method and didn't look at the class 👍

I want to look this over a bit more before I merge but I think it's good. Thanks!

eileencodes added a commit that referenced this pull request Sep 9, 2015
HasManyAssociation: moved half of counter cache code to reflection
@eileencodes eileencodes merged commit d73d1a2 into rails:master Sep 9, 2015
@bogdan bogdan deleted the refactor-has-many-counter-cache branch September 14, 2015 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants