Hi i have these classes:
class Core < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
belongs_to :image, :class_name => 'Multimedia', :foreign_key => 'image_id'
end
class Place < ActiveRecord::Base
has_one :core, :as => :resource
end
If i try do launch this:
a = Place.find(5)
a.name ="a"
a.core.image_id = 24
a.save
name is saved. image_id no
i want save automatically all changes in records in relationship with place class at a.save command. is possible?
thanks
Use
:autosave => trueSee section titled One-to-many Example for ActiveRecord::AutosaveAssociation.
You’ll want something like:
Disclaimer:
The
:autosave => trueshould be used on the “parent” Object. It works great withhas_oneandhas_many, but I’ve run into great difficulty attempting to use it on abelongs_to. relationship.