save object associate to another object automatically

Posted by Luca Romagnoli on Stack Overflow See other posts from Stack Overflow or by Luca Romagnoli
Published on 2010-03-28T18:52:46Z Indexed on 2010/03/28 19:43 UTC
Read the original article Hit count: 170

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby