Hi there,
I would like to find more information about query caching, or about the
concept behind the following behavior, in a “User has many Groups
through Memberships” association.
Let me show you an example.
Base :
user = User.find_by_email(‘[email protected]’)
group = List.create( :title => “First group” )
group2 = List.create( :title => “Second group” )
if I do this :
Membership.create(:group => group, :user => user)
Membership.create(:group => group2, :user => user)
user.groups.each do |g| puts g.title end
the result is as expected
First group
Second group
But if do this :
Membership.create(:group => group, :user => user)
user.groups.each do |g| puts g.title end
Membership.create(:group => group2, :user => user)
user.groups.each do |g| puts g.title end
the result is :
First group
First group
instead of
First group
First group
Second group
What’s the magic behind that ?
Also, what’s the best way to create new memberships and avoid troubles ?
Thanks