Module: Mongoid::Keys::ClassMethods
- Defined in:
- lib/mongoid/keys.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#identity(options = {}) ⇒ Object
Used for telling Mongoid on a per model basis whether to override the default
BSON::ObjectId
and use a different type. -
#key(*fields) ⇒ Object
Defines the field that will be used for the id of this
Document
. -
#using_object_ids? ⇒ true, false
Convenience method for determining if we are using
BSON::ObjectIds
as our id.
Instance Method Details
#identity(options = {}) ⇒ Object
Used for telling Mongoid on a per model basis whether to override the default BSON::ObjectId
and use a different type. This will be expanded in the future for requiring a PkFactory if the type is not a BSON::ObjectId
or String
.
78 79 80 81 |
# File 'lib/mongoid/keys.rb', line 78 def identity( = {}) fields["_id"].type = [:type] @object_ids = id_is_object end |
#key(*fields) ⇒ Object
Defines the field that will be used for the id of this Document
. This set the id of this Document
before save to a parameterized version of the field that was supplied. This is good for use for readable URLS in web applications.
97 98 99 100 101 |
# File 'lib/mongoid/keys.rb', line 97 def key(*fields) self.primary_key = fields identity(:type => String) set_callback(:save, :around, :set_composite_key) end |
#using_object_ids? ⇒ true, false
Convenience method for determining if we are using BSON::ObjectIds
as our id.
112 113 114 |
# File 'lib/mongoid/keys.rb', line 112 def using_object_ids? @object_ids ||= id_is_object end |