ruby on rails 4 - Polymorphic relationship - what is stored in the type attribute? -



ruby on rails 4 - Polymorphic relationship - what is stored in the type attribute? -

let's have polymorphic relationship this:

class image < activerecord::base belongs_to :imageable, polymorphic: true end class employee < activerecord::base has_many :pretty_pictures, as: :imageable end class productinvoice < activerecord::base has_many :pretty_pictures, as: :imageable end

and migration image model:

class createpictures < activerecord::migration def alter create_table :pictures |t| t.string :name t.references :imageable, polymorphic: true t.timestamps end end end

let's have @product_invoice :id of 1 , have @picture belongs product. know @picture.imagable_id should equal 1, value stored in @picture.imagable_type be?

'productinvoice' 'productinvoices' 'product_invoice' 'product_invoices'

via g.b in comments

'productinvoice'

ruby-on-rails-4 polymorphism has-many polymorphic-associations belongs-to

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -