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

Already on GitHub? Sign in to your account

Association autorefresh plugin #17

1 commit merged into from Feb 11, 2011


None yet
2 participants

jfirebaugh commented Feb 10, 2011

No description provided.


jeremyevans commented Feb 10, 2011

This causes a performance hit for every many_to_one association access. Instead, the implementation should just clear the cache for any related associations when the foreign key changes. Also, I think stale_associations would be a better plugin name than association_autorefresh.

Add AssociationAutoreloading plugin.
The AssociationAutoreloading plugin makes many_to_one association
accessor methods automatically reload the cached object whenever
the association's foreign key is modified:

   album = Album.first
   album.artist_id #=> 1
   album.artist # caches associated artist
   album.artist_id = 2
   album.artist # reloads associated artist

jfirebaugh commented Feb 10, 2011

Pushed a new version using attribute setters.

I'm not crazy about stale_associations as a name. If I'm a user I'd be thinking, why would I want my associations to be stale? I think it's clearer to have a name that describes what the plugin does in the positive, rather than the problem it corrects, in the negative. That said, the correct verb here is "reload", not "refresh", so I went with association_autoreloading. This also is a closer match with other association-related plugins (association_dependencies, association_proxies, etc.), and "loading" matches with tactical_eager_loading.


jeremyevans commented Feb 11, 2011

I looked at the patch earlier today, it looks good. I'm in the middle of writing a tiny_tds adapter, which is the only reason I didn't try merging it today. I'll try to merge this tomorrow, and assuming no problems, it will be committed.

I still don't like the plugin name, as autoreloading is not what the plugin actually does (it clears the cache, it doesn't reload). But since you wrote the support, you get to name it. :)

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment