This project is archived and is in readonly mode.
ActiveRecord caching has_many :through
-
Jon Leighton
- State changed from new to invalid
- Importance changed from to Low
Thanks for the bug report.
In the example you've given, the first time you run
me.favorite_pets, it goes to the database and get the answer (empty). It then remembers the answer until there is a reason to forget it.When you do
Favorite.new, yourmeobject doesn't know anything about it. So when you runme.favorite_petsagain it just returns the same result because it doesn't realise that the result has changed.To fix your code, you could:
- Run
me.favorite_pets(true)to force the association to be reloaded - Create the
Favoriteobject by doingme.favorites.new(:favorite_thing => sparky)
-
Barak
Hi Jon, thanks for the reply.
I wasn't aware that me.favorite_pets(true) existed. Very useful thing to know. Thanks again.