rails/rails — Issue #4024: nested attributes on override relationship
Author: acetinick
Created: 2011-12-18 23:18:03+00:00
State: open

I had some issues with updating a record with nested attributes when my model was using inheritance to update a overridden relationship.

eg.

class Flight < Plan
attr_accessible :travels_attributes
has_many :travels, :class_name => "FlightTravel", :foreign_key => "plan_id", :dependent => :destroy
accepts_nested_attributes_for :travels, :allow_destroy => true
End

class Travel < ActiveRecord::Base
attr_accessible :segments_attributes
has_many :segments, :class_name => "TravelSegment", :dependent => :destroy, :foreign_key => "flight_travel_id"
accepts_nested_attributes_for :segments, :allow_destroy => true
end

class FlightTravel < Travel
attr_accessible :segments_attributes

has_many :segments, :class_name => "FlightSegment", :dependent => :destroy, :foreign_key => "flight_travel_id"
accepts_nested_attributes_for :segments, :allow_destroy => true
end

class FlightSegment < ActiveRecord::Base

end

class TravelSegment < ActiveRecord::Base

end

Now when I try to call flight.update_attributes(:travels_attributes => {...}) in the console will update the object correctly with the right values.

I call flight.save and it doesn't do anything, and for some reason just skips updating the nested associations. This is a defect ? or is my implementation wrong ?