26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/mongo_db/object/object_serializer.rb', line 26
def insert opts, collection
opts, validate, callbacks = parse_object_options opts
return false if callbacks and !run_callbacks(objects, [:before, :validate], [:before, :save], [:before, :create])
return false if validate and !valid?
doc = to_document
collection.insert_without_object doc, opts
id = doc[:_id] || doc['_id'] || raise("internal error: no id after document insertion (#{doc})!")
object.instance_variable_set :@_id, id
update_internal_state!
run_callbacks(objects, [:after, :create], [:after, :save], [:after, :validate]) if callbacks
true
end
|