Marten::DB::Field::Polymorphic
Inherits Marten::DB::Field::Base < Reference < Object
Represents a polymorphic field.
A polymorphic field is a field that can store a reference to a record of any of the specified types:
class MyModel < Marten::Model
# Other fields...
field :owner, :polymorphic, to: [User, Group]
end
Constructors
Instance methods
Extracts the field value from a DB result set and returns the right object corresponding to this value.
Returns true if the field is a relation.
By default this method will always return false. It should be overridden if the field is intended to handle
a relation with another model (eg. like many to one or one to one fields).
Returns the name of the relation on the model associated with the field.
This method will raise a NotImplementedError exception by default and should only be overridden if the
#relation? method returns true (this is the case for fields such as many to one, one to one, etc).