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
.
103 104 105 106 107 |
# File 'lib/mongoid/keys.rb', line 103 def identity( = {}) type = [:type] replace_field("_id", type) self.using_object_ids = (type == BSON::ObjectId) 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.
123 124 125 126 127 128 |
# File 'lib/mongoid/keys.rb', line 123 def key(*fields) self.primary_key = fields self.key_formatter = block_given? ? Proc.new : nil 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.
139 140 141 |
# File 'lib/mongoid/keys.rb', line 139 def using_object_ids? using_object_ids end |