Module: PrimaryKeyFactory

Defined in:
lib/yodel/models/core/mongo/primary_key_factory.rb

Class Method Summary collapse

Class Method Details

.create_pk(doc) ⇒ Object

The default mongo primary key factory (BSON::ObjectId) creates ids with symbol keys. Yodel uses string keys (since records are retrieved with string keys) so Yodel mongo collections use this pk factory instead.



5
6
7
# File 'lib/yodel/models/core/mongo/primary_key_factory.rb', line 5

def self.create_pk(doc)
  doc.has_key?('_id') ? doc : doc.merge!('_id' => self.pk)
end

.pkObject



9
10
11
# File 'lib/yodel/models/core/mongo/primary_key_factory.rb', line 9

def self.pk
  BSON::ObjectId.new
end