Module | Mongoid::Fields::ClassMethods |
In: |
lib/mongoid/fields.rb
|
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
@example Define a field.
field :score, :type => Integer, :default => 0
@param [ Symbol ] name The name of the field. @param [ Hash ] options The options to pass to the field.
@option options [ Class ] :type The type of the field. @option options [ String ] :label The label for the field. @option options [ Object, Proc ] :default The field‘s default
@return [ Field ] The generated field
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behaviour of the old class_inheritable_accessor that was deprecated in Rails edge.
@example Inherit from this class.
Person.inherited(Doctor)
@param [ Class ] subclass The inheriting class.
@since 2.0.0.rc.6
Is the field with the provided name a BSON::ObjectId?
@example Is the field a BSON::ObjectId?
Person.object_id_field?(:name)
@param [ String, Symbol ] name The name of the field.
@return [ true, false ] If the field is a BSON::ObjectId.
@since 2.2.0
Determine if the field name is allowed, if not raise an error.
@example Check the field name.
Model.check_field_name!(:collection)
@param [ Symbol ] name The field name.
@raise [ Errors::InvalidField ] If the name is not allowed.
@since 2.1.8
Create the field accessors.
@example Generate the accessors.
Person.create_accessors(:name, "name") person.name #=> returns the field person.name = "" #=> sets the field person.name? #=> Is the field present?
@param [ Symbol ] name The name of the field. @param [ Symbol ] meth The name of the accessor. @param [ Hash ] options The options.