Polymorphic

Let a model belong to more than one model.

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

class MenuItem < ActiveRecord::Base
  has_many :media, as: :imageable
end
# rails 4.2+
$ rails generate migration AddPolymorphicxxxableToTable imageable:references{polymorphic}

Reference

results matching ""

    No results matching ""