Say I have these two classes
class Gadget < ActiveRecord::Base
has_many :widgets
end
class Widget < ActiveRecord::Base
belongs_to :gadget
# table has string attribute .color
end
And let's say that the database contains one gadget and one widget, each with id = 1, and the widget has a color of nil.
Modifying a record retrieved with .find
g = Gadget.first
w = g.widgets.find { |widg| widg.id == 1 }
w.color = "blue"
g.widgets.first.color
=> "blue"
Modifying a record retrieved with .find_by
g = Gadget.first
w = g.widgets.find_by(id: 1)
w.color = "blue"
g.widgets.first.color
=> nil
I can't account for this difference.