Does anyone know how to do a polymorphic association in Mongoid
that is of the relational favor but not the embedding one.
For instance this is my Ass
Answering to an ancient post, but someone may find it useful.
Now there's also a polymorphic belongs_to
:
class Action
include Mongoid::Document
include Mongoid::Timestamps::Created
field :action, type: Symbol
belongs_to :subject, :polymorphic => true
end
class User
include Mongoid::Document
include Mongoid::Timestamps
field :username, type: String
has_many :actions, :as => :subject
end
class Company
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
has_many :actions, :as => :subject
end