This project is archived and is in readonly mode.
Changing foreign key doesn't set relationship as dirty
-
Darren
I have come across a problem which I believe is closely related to this.
If I have a model that belongs_to another, and requires the presence of the relationship (i.e., a valid non-null foreign key), I can get AR to save invalid records in the database.
For example, with this...
Class Parent < AR::B end class Child < AR::B belongs_to :parent # using parent_id validates_presence_of :parent end./script/console... # child = Child.new # child.valid? # false # child.parent_id = Parent.first.id # a valid parent # child.valid? # true # child.parent_id = 9999 # doesn't exist # child.valid? # true # child.save # true # child.reload # child.parent_id # 9999 # child.parent # nil # child.valid? # false -
Frederick Cheung
- State changed from new to duplicate