inverse_of does not work
Closed this issue · 3 comments
heguchi commented
I have two models like below:
model
class Parent < ApplicationRecord
has_many :children
end
class Child < ApplicationRecord
belongs_to :parent
end
Without goldiloader, "inverse_of" automatically works.
parent = Parent.create
parent.children.create
parent.children.first.parent.object_id == parent.object_id # true
parent.children.each { |child| p child.parent.object_id == parent.object_id } # true
parent.reload
parent.children.first.parent.object_id == parent.object_id # true
parent.children.each { |child| p child.parent.object_id == parent.object_id } # true
But, "inverse_of" does not work correctly with goldiloader
parent = Parent.create
parent.children.create
parent.children.first.parent.object_id == parent.object_id # true
parent.children.each { |child| p child.parent.object_id == parent.object_id } # true
parent.reload
parent.children.first.parent.object_id == parent.object_id # true
parent.children.each { |child| p child.parent.object_id == parent.object_id } # **false**
rails: 5.0.2
goldiloader: 0.0.11
jturkel commented
I've confirmed this is an issue when running with Rails 5.0.2 but it works fine with Rails 4.2.7. I'll look into it more shortly.