jeudi 30 juillet 2015

change type in polymorphic association in rails

I am new to rails and I'm using rails Polymorphic association and I ran into a problem I have two models EmployeeTable and ProductTable. Both have some picture in Picture Model

class Picture < ActiveRecord::Base
   belongs_to :imageable, polymorphic: true
end

class EmployeeTable < ActiveRecord::Base
   has_many :pictures, as: :imageable
end

class ProductTable < ActiveRecord::Base
  has_many :pictures, as: :imageable
end

there are two column in Picture imagable_id and imagable_type. When I create an entry in table it stores imagable_type as either "EmployeeTable" or "ProductTable". Can I change these name to any different Names like "employee" and "product".

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire