mongoid 1.9.5 → 2.0.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/.watchr +29 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/caliper.yml +4 -0
- data/lib/mongoid.rb +20 -9
- data/lib/mongoid/associations.rb +100 -123
- data/lib/mongoid/associations/belongs_to_related.rb +3 -2
- data/lib/mongoid/associations/{embeds_many.rb → embed_many.rb} +29 -90
- data/lib/mongoid/associations/{embeds_one.rb → embed_one.rb} +7 -8
- data/lib/mongoid/associations/embedded_in.rb +4 -12
- data/lib/mongoid/associations/has_many_related.rb +4 -52
- data/lib/mongoid/associations/has_one_related.rb +4 -8
- data/lib/mongoid/associations/meta_data.rb +1 -2
- data/lib/mongoid/associations/options.rb +1 -6
- data/lib/mongoid/associations/proxy.rb +21 -14
- data/lib/mongoid/attributes.rb +13 -33
- data/lib/mongoid/callbacks.rb +11 -16
- data/lib/mongoid/collection.rb +3 -4
- data/lib/mongoid/collections/master.rb +2 -3
- data/lib/mongoid/collections/mimic.rb +46 -0
- data/lib/mongoid/collections/slaves.rb +2 -3
- data/lib/mongoid/commands.rb +161 -0
- data/lib/mongoid/commands/create.rb +19 -0
- data/lib/mongoid/commands/delete.rb +16 -0
- data/lib/mongoid/commands/delete_all.rb +23 -0
- data/lib/mongoid/commands/deletion.rb +18 -0
- data/lib/mongoid/commands/destroy.rb +17 -0
- data/lib/mongoid/commands/destroy_all.rb +23 -0
- data/lib/mongoid/commands/save.rb +29 -0
- data/lib/mongoid/components.rb +6 -4
- data/lib/mongoid/config.rb +15 -134
- data/lib/mongoid/contexts.rb +1 -1
- data/lib/mongoid/contexts/enumerable.rb +1 -1
- data/lib/mongoid/contexts/mongo.rb +1 -1
- data/lib/mongoid/contexts/paging.rb +2 -10
- data/lib/mongoid/criterion/inclusion.rb +0 -17
- data/lib/mongoid/criterion/optional.rb +1 -1
- data/lib/mongoid/cursor.rb +1 -0
- data/lib/mongoid/document.rb +45 -49
- data/lib/mongoid/errors.rb +1 -32
- data/lib/mongoid/extensions.rb +10 -12
- data/lib/mongoid/extensions/array/conversions.rb +6 -8
- data/lib/mongoid/extensions/big_decimal/conversions.rb +2 -2
- data/lib/mongoid/extensions/boolean/conversions.rb +2 -8
- data/lib/mongoid/extensions/date/conversions.rb +4 -13
- data/lib/mongoid/extensions/datetime/conversions.rb +6 -1
- data/lib/mongoid/extensions/float/conversions.rb +1 -5
- data/lib/mongoid/extensions/hash/assimilation.rb +3 -12
- data/lib/mongoid/extensions/hash/conversions.rb +4 -34
- data/lib/mongoid/extensions/integer/conversions.rb +1 -5
- data/lib/mongoid/extensions/nil/assimilation.rb +0 -4
- data/lib/mongoid/extensions/object/conversions.rb +2 -8
- data/lib/mongoid/extensions/objectid/conversions.rb +1 -1
- data/lib/mongoid/extensions/string/conversions.rb +1 -1
- data/lib/mongoid/extensions/symbol/inflections.rb +1 -1
- data/lib/mongoid/extensions/time/conversions.rb +18 -0
- data/lib/mongoid/factory.rb +1 -2
- data/lib/mongoid/field.rb +2 -9
- data/lib/mongoid/fields.rb +7 -11
- data/lib/mongoid/finders.rb +2 -2
- data/lib/mongoid/identity.rb +4 -4
- data/lib/mongoid/indexes.rb +7 -10
- data/lib/mongoid/memoization.rb +2 -8
- data/lib/mongoid/named_scope.rb +5 -0
- data/lib/mongoid/observable.rb +1 -1
- data/lib/mongoid/paths.rb +22 -30
- data/lib/mongoid/state.rb +21 -28
- data/lib/mongoid/timestamps.rb +1 -1
- data/lib/mongoid/validations.rb +51 -0
- data/lib/mongoid/validations/associated.rb +32 -0
- data/lib/mongoid/validations/locale/en.yml +4 -0
- data/lib/mongoid/validations/uniqueness.rb +22 -0
- data/lib/mongoid/versioning.rb +1 -2
- data/mongoid.gemspec +408 -0
- data/perf/benchmark.rb +77 -0
- data/spec/integration/mongoid/associations_spec.rb +340 -0
- data/spec/integration/mongoid/attributes_spec.rb +22 -0
- data/spec/integration/mongoid/commands_spec.rb +227 -0
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +33 -0
- data/spec/integration/mongoid/criteria_spec.rb +272 -0
- data/spec/integration/mongoid/document_spec.rb +650 -0
- data/spec/integration/mongoid/extensions_spec.rb +22 -0
- data/spec/integration/mongoid/finders_spec.rb +119 -0
- data/spec/integration/mongoid/inheritance_spec.rb +137 -0
- data/spec/integration/mongoid/named_scope_spec.rb +46 -0
- data/spec/models/address.rb +39 -0
- data/spec/models/animal.rb +6 -0
- data/spec/models/callbacks.rb +18 -0
- data/spec/models/comment.rb +8 -0
- data/spec/models/country_code.rb +6 -0
- data/spec/models/employer.rb +5 -0
- data/spec/models/game.rb +7 -0
- data/spec/models/inheritance.rb +56 -0
- data/spec/models/location.rb +5 -0
- data/spec/models/mixed_drink.rb +4 -0
- data/spec/models/name.rb +13 -0
- data/spec/models/namespacing.rb +11 -0
- data/spec/models/patient.rb +4 -0
- data/spec/models/person.rb +99 -0
- data/spec/models/pet.rb +7 -0
- data/spec/models/pet_owner.rb +6 -0
- data/spec/models/phone.rb +7 -0
- data/spec/models/post.rb +15 -0
- data/spec/models/translation.rb +5 -0
- data/spec/models/vet_visit.rb +5 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +145 -0
- data/spec/unit/mongoid/associations/embed_many_spec.rb +516 -0
- data/spec/unit/mongoid/associations/embed_one_spec.rb +282 -0
- data/spec/unit/mongoid/associations/embedded_in_spec.rb +193 -0
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +418 -0
- data/spec/unit/mongoid/associations/has_one_related_spec.rb +179 -0
- data/spec/unit/mongoid/associations/meta_data_spec.rb +88 -0
- data/spec/unit/mongoid/associations/options_spec.rb +192 -0
- data/spec/unit/mongoid/associations_spec.rb +595 -0
- data/spec/unit/mongoid/attributes_spec.rb +507 -0
- data/spec/unit/mongoid/callbacks_spec.rb +55 -0
- data/spec/unit/mongoid/collection_spec.rb +187 -0
- data/spec/unit/mongoid/collections/cyclic_iterator_spec.rb +75 -0
- data/spec/unit/mongoid/collections/master_spec.rb +41 -0
- data/spec/unit/mongoid/collections/mimic_spec.rb +43 -0
- data/spec/unit/mongoid/collections/slaves_spec.rb +81 -0
- data/spec/unit/mongoid/commands/create_spec.rb +31 -0
- data/spec/unit/mongoid/commands/delete_all_spec.rb +58 -0
- data/spec/unit/mongoid/commands/delete_spec.rb +38 -0
- data/spec/unit/mongoid/commands/destroy_all_spec.rb +21 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +51 -0
- data/spec/unit/mongoid/commands/save_spec.rb +107 -0
- data/spec/unit/mongoid/commands_spec.rb +270 -0
- data/spec/unit/mongoid/config_spec.rb +172 -0
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +421 -0
- data/spec/unit/mongoid/contexts/mongo_spec.rb +682 -0
- data/spec/unit/mongoid/contexts_spec.rb +25 -0
- data/spec/unit/mongoid/criteria_spec.rb +824 -0
- data/spec/unit/mongoid/criterion/complex_spec.rb +19 -0
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +91 -0
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +219 -0
- data/spec/unit/mongoid/criterion/optional_spec.rb +319 -0
- data/spec/unit/mongoid/cursor_spec.rb +74 -0
- data/spec/unit/mongoid/deprecation_spec.rb +24 -0
- data/spec/unit/mongoid/document_spec.rb +818 -0
- data/spec/unit/mongoid/errors_spec.rb +103 -0
- data/spec/unit/mongoid/extensions/array/accessors_spec.rb +50 -0
- data/spec/unit/mongoid/extensions/array/assimilation_spec.rb +24 -0
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +35 -0
- data/spec/unit/mongoid/extensions/array/parentization_spec.rb +20 -0
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +22 -0
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +22 -0
- data/spec/unit/mongoid/extensions/boolean/conversions_spec.rb +49 -0
- data/spec/unit/mongoid/extensions/date/conversions_spec.rb +102 -0
- data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +67 -0
- data/spec/unit/mongoid/extensions/float/conversions_spec.rb +61 -0
- data/spec/unit/mongoid/extensions/hash/accessors_spec.rb +184 -0
- data/spec/unit/mongoid/extensions/hash/assimilation_spec.rb +46 -0
- data/spec/unit/mongoid/extensions/hash/conversions_spec.rb +21 -0
- data/spec/unit/mongoid/extensions/hash/criteria_helpers_spec.rb +17 -0
- data/spec/unit/mongoid/extensions/hash/scoping_spec.rb +14 -0
- data/spec/unit/mongoid/extensions/integer/conversions_spec.rb +61 -0
- data/spec/unit/mongoid/extensions/nil/assimilation_spec.rb +24 -0
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +57 -0
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +34 -0
- data/spec/unit/mongoid/extensions/string/conversions_spec.rb +17 -0
- data/spec/unit/mongoid/extensions/string/inflections_spec.rb +208 -0
- data/spec/unit/mongoid/extensions/symbol/inflections_spec.rb +91 -0
- data/spec/unit/mongoid/extensions/time/conversions_spec.rb +70 -0
- data/spec/unit/mongoid/extras_spec.rb +102 -0
- data/spec/unit/mongoid/factory_spec.rb +31 -0
- data/spec/unit/mongoid/field_spec.rb +143 -0
- data/spec/unit/mongoid/fields_spec.rb +181 -0
- data/spec/unit/mongoid/finders_spec.rb +404 -0
- data/spec/unit/mongoid/identity_spec.rb +109 -0
- data/spec/unit/mongoid/indexes_spec.rb +93 -0
- data/spec/unit/mongoid/javascript_spec.rb +48 -0
- data/spec/unit/mongoid/matchers/all_spec.rb +27 -0
- data/spec/unit/mongoid/matchers/default_spec.rb +27 -0
- data/spec/unit/mongoid/matchers/exists_spec.rb +56 -0
- data/spec/unit/mongoid/matchers/gt_spec.rb +39 -0
- data/spec/unit/mongoid/matchers/gte_spec.rb +49 -0
- data/spec/unit/mongoid/matchers/in_spec.rb +27 -0
- data/spec/unit/mongoid/matchers/lt_spec.rb +39 -0
- data/spec/unit/mongoid/matchers/lte_spec.rb +49 -0
- data/spec/unit/mongoid/matchers/ne_spec.rb +27 -0
- data/spec/unit/mongoid/matchers/nin_spec.rb +27 -0
- data/spec/unit/mongoid/matchers/size_spec.rb +27 -0
- data/spec/unit/mongoid/matchers_spec.rb +329 -0
- data/spec/unit/mongoid/memoization_spec.rb +75 -0
- data/spec/unit/mongoid/named_scope_spec.rb +123 -0
- data/spec/unit/mongoid/observable_spec.rb +46 -0
- data/spec/unit/mongoid/paths_spec.rb +124 -0
- data/spec/unit/mongoid/scope_spec.rb +240 -0
- data/spec/unit/mongoid/state_spec.rb +83 -0
- data/spec/unit/mongoid/timestamps_spec.rb +25 -0
- data/spec/unit/mongoid/validations/associated_spec.rb +103 -0
- data/spec/unit/mongoid/validations/uniqueness_spec.rb +47 -0
- data/spec/unit/mongoid/validations_spec.rb +190 -0
- data/spec/unit/mongoid/versioning_spec.rb +41 -0
- data/spec/unit/mongoid_spec.rb +46 -0
- metadata +316 -110
- data/lib/mongoid/collections.rb +0 -41
- data/lib/mongoid/concern.rb +0 -31
- data/lib/mongoid/dirty.rb +0 -253
- data/lib/mongoid/extensions/time_conversions.rb +0 -35
- data/lib/mongoid/persistence.rb +0 -222
- data/lib/mongoid/persistence/command.rb +0 -39
- data/lib/mongoid/persistence/insert.rb +0 -50
- data/lib/mongoid/persistence/insert_embedded.rb +0 -38
- data/lib/mongoid/persistence/remove.rb +0 -39
- data/lib/mongoid/persistence/remove_all.rb +0 -37
- data/lib/mongoid/persistence/remove_embedded.rb +0 -50
- data/lib/mongoid/persistence/update.rb +0 -63
- data/lib/mongoid/version.rb +0 -4
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Persistence commands extend from this class to get basic functionality on
|
5
|
-
# initialization.
|
6
|
-
class Command
|
7
|
-
attr_reader \
|
8
|
-
:collection,
|
9
|
-
:document,
|
10
|
-
:klass,
|
11
|
-
:options,
|
12
|
-
:selector,
|
13
|
-
:validate
|
14
|
-
|
15
|
-
# Initialize the persistence +Command+.
|
16
|
-
#
|
17
|
-
# Options:
|
18
|
-
#
|
19
|
-
# document_or_class: The +Document+ or +Class+ to get the collection.
|
20
|
-
# validate: Is the document to be validated.
|
21
|
-
# selector: Optional selector to use in query.
|
22
|
-
#
|
23
|
-
# Example:
|
24
|
-
#
|
25
|
-
# <tt>DeleteAll.new(Person, false, {})</tt>
|
26
|
-
def initialize(document_or_class, validate = true, selector = {})
|
27
|
-
if document_or_class.is_a?(Mongoid::Document)
|
28
|
-
@document = document_or_class
|
29
|
-
@collection = @document.embedded? ? @document._root.collection : @document.collection
|
30
|
-
else
|
31
|
-
@klass = document_or_class
|
32
|
-
@collection = @klass.collection
|
33
|
-
end
|
34
|
-
@selector, @validate = selector, validate
|
35
|
-
@options = { :safe => Mongoid.persist_in_safe_mode }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Insert is a persistence command responsible for taking a document that
|
5
|
-
# has not been saved to the database and saving it.
|
6
|
-
#
|
7
|
-
# The underlying query resembles the following MongoDB query:
|
8
|
-
#
|
9
|
-
# collection.insert(
|
10
|
-
# { "_id" : 1, "field" : "value" },
|
11
|
-
# false
|
12
|
-
# );
|
13
|
-
class Insert < Command
|
14
|
-
# Insert the new document in the database. This delegates to the standard
|
15
|
-
# MongoDB collection's insert command.
|
16
|
-
#
|
17
|
-
# Example:
|
18
|
-
#
|
19
|
-
# <tt>Insert.persist</tt>
|
20
|
-
#
|
21
|
-
# Returns:
|
22
|
-
#
|
23
|
-
# The +Document+, whether the insert succeeded or not.
|
24
|
-
def persist
|
25
|
-
return @document if @validate && !@document.valid?
|
26
|
-
@document.run_callbacks(:before_create)
|
27
|
-
@document.run_callbacks(:before_save)
|
28
|
-
if insert
|
29
|
-
@document.new_record = false
|
30
|
-
# TODO: All child document new_record flags must get set to false
|
31
|
-
# here or somewhere - this will cause problems.
|
32
|
-
@document.move_changes
|
33
|
-
@document.run_callbacks(:after_create)
|
34
|
-
@document.run_callbacks(:after_save)
|
35
|
-
end
|
36
|
-
@document
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
# Insert the document into the database.
|
41
|
-
def insert
|
42
|
-
if @document.embedded?
|
43
|
-
Persistence::InsertEmbedded.new(@document, @validate).persist
|
44
|
-
else
|
45
|
-
@collection.insert(@document.raw_attributes, @options)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Insert is a persistence command responsible for taking a document that
|
5
|
-
# has not been saved to the database and saving it. This specific class
|
6
|
-
# handles the case when the document is embedded in another.
|
7
|
-
#
|
8
|
-
# The underlying query resembles the following MongoDB query:
|
9
|
-
#
|
10
|
-
# collection.insert(
|
11
|
-
# { "_id" : 1, "field" : "value" },
|
12
|
-
# false
|
13
|
-
# );
|
14
|
-
class InsertEmbedded < Command
|
15
|
-
# Insert the new document in the database. If the document's parent is a
|
16
|
-
# new record, we will call save on the parent, otherwise we will $push
|
17
|
-
# the document onto the parent.
|
18
|
-
#
|
19
|
-
# Example:
|
20
|
-
#
|
21
|
-
# <tt>Insert.persist</tt>
|
22
|
-
#
|
23
|
-
# Returns:
|
24
|
-
#
|
25
|
-
# The +Document+, whether the insert succeeded or not.
|
26
|
-
def persist
|
27
|
-
parent = @document._parent
|
28
|
-
if parent.new_record?
|
29
|
-
parent.insert
|
30
|
-
else
|
31
|
-
update = { @document._inserter => { @document._position => @document.raw_attributes } }
|
32
|
-
@collection.update(parent._selector, update, @options.merge(:multi => false))
|
33
|
-
end
|
34
|
-
@document.new_record = false; @document
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Remove is a persistence command responsible for deleting a document from
|
5
|
-
# the database.
|
6
|
-
#
|
7
|
-
# The underlying query resembles the following MongoDB query:
|
8
|
-
#
|
9
|
-
# collection.remove(
|
10
|
-
# { "_id" : 1 },
|
11
|
-
# false
|
12
|
-
# );
|
13
|
-
class Remove < Command
|
14
|
-
# Remove the document from the database: delegates to the MongoDB
|
15
|
-
# collection remove method.
|
16
|
-
#
|
17
|
-
# Example:
|
18
|
-
#
|
19
|
-
# <tt>Remove.persist</tt>
|
20
|
-
#
|
21
|
-
# Returns:
|
22
|
-
#
|
23
|
-
# +true+ if success, +false+ if not.
|
24
|
-
def persist
|
25
|
-
remove
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
# Remove the document from the database.
|
30
|
-
def remove
|
31
|
-
if @document.embedded?
|
32
|
-
Persistence::RemoveEmbedded.new(@document, @validate).persist
|
33
|
-
else
|
34
|
-
@collection.remove({ :_id => @document.id }, @options)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Remove is a persistence command responsible for deleting a document from
|
5
|
-
# the database.
|
6
|
-
#
|
7
|
-
# The underlying query resembles the following MongoDB query:
|
8
|
-
#
|
9
|
-
# collection.remove(
|
10
|
-
# { "field" : value },
|
11
|
-
# false
|
12
|
-
# );
|
13
|
-
class RemoveAll < Command
|
14
|
-
# Remove the document from the database: delegates to the MongoDB
|
15
|
-
# collection remove method.
|
16
|
-
#
|
17
|
-
# Example:
|
18
|
-
#
|
19
|
-
# <tt>Remove.persist</tt>
|
20
|
-
#
|
21
|
-
# Returns:
|
22
|
-
#
|
23
|
-
# +true+ if success, +false+ if not.
|
24
|
-
def persist
|
25
|
-
remove
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
# Remove the document from the database.
|
30
|
-
def remove
|
31
|
-
count = @collection.find(@selector.merge(:_type => @klass.name)).count
|
32
|
-
@collection.remove(@selector, @options)
|
33
|
-
count
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Remove is a persistence command responsible for deleting a document from
|
5
|
-
# the database.
|
6
|
-
#
|
7
|
-
# The underlying query resembles the following MongoDB query:
|
8
|
-
#
|
9
|
-
# collection.remove(
|
10
|
-
# { "_id" : 1 },
|
11
|
-
# false
|
12
|
-
# );
|
13
|
-
class RemoveEmbedded < Command
|
14
|
-
# Insert the new document in the database. If the document's parent is a
|
15
|
-
# new record, we will call save on the parent, otherwise we will $push
|
16
|
-
# the document onto the parent.
|
17
|
-
#
|
18
|
-
# Remove the document from the database. If the parent is a new record,
|
19
|
-
# it will get removed in Ruby only. If the parent is not a new record
|
20
|
-
# then either an $unset or $set will occur, depending if it's an
|
21
|
-
# embeds_one or embeds_many.
|
22
|
-
#
|
23
|
-
# Example:
|
24
|
-
#
|
25
|
-
# <tt>RemoveEmbedded.persist</tt>
|
26
|
-
#
|
27
|
-
# Returns:
|
28
|
-
#
|
29
|
-
# +true+ or +false+, depending on if the removal passed.
|
30
|
-
def persist
|
31
|
-
parent = @document._parent
|
32
|
-
parent.remove(@document)
|
33
|
-
unless parent.new_record?
|
34
|
-
update = { @document._remover => removal_selector }
|
35
|
-
@collection.update(parent._selector, update, @options.merge(:multi => false))
|
36
|
-
end; true
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
# Get the value to pass to the removal modifier.
|
41
|
-
def setter
|
42
|
-
@document._index ? @document.id : true
|
43
|
-
end
|
44
|
-
|
45
|
-
def removal_selector
|
46
|
-
@document._index ? { @document._pull => { "_id" => @document.id } } : { @document._path => setter }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Persistence #:nodoc:
|
4
|
-
# Update is a persistence command responsible for taking a document that
|
5
|
-
# has already been saved to the database and saving it, depending on
|
6
|
-
# whether or not the document has been modified.
|
7
|
-
#
|
8
|
-
# Before persisting the command will check via dirty attributes if the
|
9
|
-
# document has changed, if not, it will simply return true. If it has it
|
10
|
-
# will go through the validation steps, run callbacks, and set the changed
|
11
|
-
# fields atomically on the document. The underlying query resembles the
|
12
|
-
# following MongoDB query:
|
13
|
-
#
|
14
|
-
# collection.update(
|
15
|
-
# { "_id" : 1,
|
16
|
-
# { "$set" : { "field" : "value" },
|
17
|
-
# false,
|
18
|
-
# false
|
19
|
-
# );
|
20
|
-
#
|
21
|
-
# For embedded documents it will use the positional locator:
|
22
|
-
#
|
23
|
-
# collection.update(
|
24
|
-
# { "_id" : 1, "addresses._id" : 2 },
|
25
|
-
# { "$set" : { "addresses.$.field" : "value" },
|
26
|
-
# false,
|
27
|
-
# false
|
28
|
-
# );
|
29
|
-
#
|
30
|
-
class Update < Command
|
31
|
-
# Persist the document that is to be updated to the database. This will
|
32
|
-
# only write changed fields via MongoDB's $set modifier operation.
|
33
|
-
#
|
34
|
-
# Example:
|
35
|
-
#
|
36
|
-
# <tt>Update.persist</tt>
|
37
|
-
#
|
38
|
-
# Returns:
|
39
|
-
#
|
40
|
-
# +true+ or +false+, depending on validation.
|
41
|
-
def persist
|
42
|
-
return false if validate && !@document.valid?
|
43
|
-
@document.run_callbacks(:before_save)
|
44
|
-
@document.run_callbacks(:before_update)
|
45
|
-
if update
|
46
|
-
@document.move_changes
|
47
|
-
@document.run_callbacks(:after_save)
|
48
|
-
@document.run_callbacks(:after_update)
|
49
|
-
else
|
50
|
-
return false
|
51
|
-
end; true
|
52
|
-
end
|
53
|
-
|
54
|
-
protected
|
55
|
-
# Update the document in the database atomically.
|
56
|
-
def update
|
57
|
-
if @document.changed?
|
58
|
-
@collection.update(@document._selector, { "$set" => @document.setters }, @options.merge(:multi => false))
|
59
|
-
end; true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/mongoid/version.rb
DELETED