mongoid 8.0.1 → 8.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/config/locales/en.yml +1 -0
- data/lib/mongoid/association/accessors.rb +6 -6
- data/lib/mongoid/association/bindable.rb +2 -2
- data/lib/mongoid/association/constrainable.rb +0 -1
- data/lib/mongoid/association/embedded/batchable.rb +5 -5
- data/lib/mongoid/association/embedded/cyclic.rb +1 -1
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -10
- data/lib/mongoid/association/embedded/embeds_many.rb +2 -2
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
- data/lib/mongoid/association/embedded/embeds_one.rb +3 -3
- data/lib/mongoid/association/many.rb +6 -7
- data/lib/mongoid/association/nested/many.rb +3 -3
- data/lib/mongoid/association/nested/nested_buildable.rb +4 -4
- data/lib/mongoid/association/nested/one.rb +5 -5
- data/lib/mongoid/association/one.rb +2 -2
- data/lib/mongoid/association/options.rb +9 -9
- data/lib/mongoid/association/proxy.rb +2 -3
- data/lib/mongoid/association/referenced/auto_save.rb +1 -1
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -6
- data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/eager.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -10
- data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -9
- data/lib/mongoid/association/referenced/has_many.rb +3 -3
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +5 -5
- data/lib/mongoid/association/referenced/has_one/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_one.rb +3 -3
- data/lib/mongoid/association/referenced/syncable.rb +2 -2
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/association/relatable.rb +6 -6
- data/lib/mongoid/association.rb +5 -5
- data/lib/mongoid/atomic/modifiers.rb +2 -2
- data/lib/mongoid/attributes/dynamic.rb +3 -3
- data/lib/mongoid/attributes/nested.rb +5 -5
- data/lib/mongoid/attributes/processing.rb +1 -1
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/attributes.rb +13 -13
- data/lib/mongoid/changeable.rb +5 -5
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/validators/storage.rb +3 -3
- data/lib/mongoid/config/validators/client.rb +6 -6
- data/lib/mongoid/config.rb +7 -7
- data/lib/mongoid/contextual/aggregable/memory.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +4 -4
- data/lib/mongoid/contextual/aggregable/none.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +7 -7
- data/lib/mongoid/contextual/memory.rb +5 -5
- data/lib/mongoid/contextual/mongo.rb +14 -14
- data/lib/mongoid/contextual/none.rb +2 -2
- data/lib/mongoid/contextual/queryable.rb +1 -1
- data/lib/mongoid/contextual.rb +2 -2
- data/lib/mongoid/criteria/findable.rb +7 -4
- data/lib/mongoid/criteria/includable.rb +1 -1
- data/lib/mongoid/criteria/permission.rb +1 -1
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/string.rb +3 -3
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +1 -1
- data/lib/mongoid/criteria/queryable/key.rb +3 -3
- data/lib/mongoid/criteria/queryable/optional.rb +2 -2
- data/lib/mongoid/criteria/queryable/options.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +1 -1
- data/lib/mongoid/criteria/queryable/selectable.rb +3 -3
- data/lib/mongoid/criteria/queryable/selector.rb +3 -3
- data/lib/mongoid/criteria/queryable/smash.rb +1 -1
- data/lib/mongoid/criteria/queryable.rb +1 -1
- data/lib/mongoid/criteria/scopable.rb +2 -2
- data/lib/mongoid/criteria.rb +14 -9
- data/lib/mongoid/deprecable.rb +1 -1
- data/lib/mongoid/document.rb +2 -2
- data/lib/mongoid/equality.rb +12 -12
- data/lib/mongoid/errors/document_not_found.rb +5 -5
- data/lib/mongoid/errors/invalid_config_option.rb +1 -1
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -1
- data/lib/mongoid/errors/invalid_field.rb +1 -1
- data/lib/mongoid/errors/invalid_relation.rb +1 -1
- data/lib/mongoid/errors/invalid_relation_option.rb +1 -1
- data/lib/mongoid/errors/invalid_session_use.rb +1 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +3 -3
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -1
- data/lib/mongoid/errors/no_client_database.rb +1 -1
- data/lib/mongoid/errors/no_client_hosts.rb +1 -1
- data/lib/mongoid/errors/readonly_attribute.rb +1 -1
- data/lib/mongoid/errors/unknown_attribute.rb +1 -1
- data/lib/mongoid/extensions/array.rb +1 -1
- data/lib/mongoid/extensions/false_class.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/extensions/module.rb +1 -1
- data/lib/mongoid/extensions/object.rb +6 -6
- data/lib/mongoid/extensions/string.rb +9 -9
- data/lib/mongoid/extensions/symbol.rb +1 -1
- data/lib/mongoid/extensions/true_class.rb +1 -1
- data/lib/mongoid/fields/foreign_key.rb +4 -4
- data/lib/mongoid/fields/localized.rb +2 -2
- data/lib/mongoid/fields/standard.rb +7 -7
- data/lib/mongoid/fields.rb +9 -9
- data/lib/mongoid/findable.rb +7 -6
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +2 -1
- data/lib/mongoid/interceptable.rb +4 -4
- data/lib/mongoid/matchable.rb +1 -1
- data/lib/mongoid/matcher.rb +12 -7
- data/lib/mongoid/persistable/creatable.rb +4 -4
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/destroyable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +2 -2
- data/lib/mongoid/persistable/unsettable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +7 -7
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +3 -3
- data/lib/mongoid/persistence_context.rb +3 -3
- data/lib/mongoid/query_cache.rb +2 -2
- data/lib/mongoid/scopable.rb +17 -15
- data/lib/mongoid/serializable.rb +10 -6
- data/lib/mongoid/stateful.rb +10 -10
- data/lib/mongoid/tasks/database.rb +0 -2
- data/lib/mongoid/threaded/lifecycle.rb +5 -5
- data/lib/mongoid/threaded.rb +9 -9
- data/lib/mongoid/timestamps/updated.rb +1 -1
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/localizable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +7 -7
- data/lib/mongoid/validatable.rb +6 -6
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/equality_spec.rb +12 -12
- data/spec/mongoid/indexable_spec.rb +23 -1
- data/spec/mongoid/scopable_spec.rb +34 -16
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
@@ -13,7 +13,7 @@ module Mongoid
|
|
13
13
|
# @example Reset the given counter cache
|
14
14
|
# post.reset_counters(:comments)
|
15
15
|
#
|
16
|
-
# @param [ Symbol
|
16
|
+
# @param [ Symbol | Array ] counters One or more counter caches to reset
|
17
17
|
def reset_counters(*counters)
|
18
18
|
self.class.with(persistence_context) do |_class|
|
19
19
|
_class.reset_counters(self, *counters)
|
@@ -30,7 +30,7 @@ module Mongoid
|
|
30
30
|
# Post.reset_counters('50e0edd97c71c17ea9000001', :comments)
|
31
31
|
#
|
32
32
|
# @param [ String ] id The id of the object that will be reset.
|
33
|
-
# @param [ Symbol
|
33
|
+
# @param [ Symbol | Array ] counters One or more counter caches to reset
|
34
34
|
def reset_counters(id, *counters)
|
35
35
|
document = id.is_a?(Document) ? id : find(id)
|
36
36
|
counters.each do |name|
|
@@ -85,7 +85,7 @@ module Mongoid
|
|
85
85
|
# loader.set_on_parent("foo", docs)
|
86
86
|
#
|
87
87
|
# @param [ ObjectId ] id parent`s id
|
88
|
-
# @param [ Document
|
88
|
+
# @param [ Document | Array ] element to push into the parent
|
89
89
|
def set_on_parent(id, element)
|
90
90
|
grouped_docs[id].each do |d|
|
91
91
|
set_relation(d, element)
|
@@ -140,7 +140,7 @@ module Mongoid
|
|
140
140
|
# loader.set_relation(doc, docs)
|
141
141
|
#
|
142
142
|
# @param [ Document ] doc The object to set the association on
|
143
|
-
# @param [ Document
|
143
|
+
# @param [ Document | Array ] element to set into the parent
|
144
144
|
def set_relation(doc, element)
|
145
145
|
doc.set_relation(@association.name, element) unless doc.blank?
|
146
146
|
end
|
@@ -21,7 +21,7 @@ module Mongoid
|
|
21
21
|
# @example Concat with other documents.
|
22
22
|
# person.posts.concat([ post_one, post_two ])
|
23
23
|
#
|
24
|
-
# @param [ Document
|
24
|
+
# @param [ Document | Array<Document> ] args Any number of documents.
|
25
25
|
#
|
26
26
|
# @return [ Array<Document> ] The loaded docs.
|
27
27
|
def <<(*args)
|
@@ -282,7 +282,7 @@ module Mongoid
|
|
282
282
|
#
|
283
283
|
# @param [ Document ] doc The document.
|
284
284
|
#
|
285
|
-
# @return [ true
|
285
|
+
# @return [ true | false ] If the document can be persisted.
|
286
286
|
def child_persistable?(doc)
|
287
287
|
(persistable? || _creating?) &&
|
288
288
|
!(doc.persisted? && _association.forced_nil_inverse?)
|
@@ -78,7 +78,7 @@ module Mongoid
|
|
78
78
|
|
79
79
|
# Are ids only saved on this side of the association?
|
80
80
|
#
|
81
|
-
# @return [ true
|
81
|
+
# @return [ true | false ] Whether this association has a forced nil inverse.
|
82
82
|
def forced_nil_inverse?
|
83
83
|
@forced_nil_inverse ||= @options.key?(:inverse_of) && !@options[:inverse_of]
|
84
84
|
end
|
@@ -131,7 +131,7 @@ module Mongoid
|
|
131
131
|
#
|
132
132
|
# @param [ Document ] doc The document to be bound.
|
133
133
|
#
|
134
|
-
# @return [ true
|
134
|
+
# @return [ true | false ] Whether the document can be bound.
|
135
135
|
def bindable?(doc)
|
136
136
|
forced_nil_inverse? || (!!inverse && doc.fields.keys.include?(foreign_key))
|
137
137
|
end
|
@@ -28,7 +28,7 @@ module Mongoid
|
|
28
28
|
#
|
29
29
|
# @param [ Enumerable ] other The other enumerable.
|
30
30
|
#
|
31
|
-
# @return [ true
|
31
|
+
# @return [ true | false ] If the objects are equal.
|
32
32
|
def ==(other)
|
33
33
|
return false unless other.respond_to?(:entries)
|
34
34
|
entries == other.entries
|
@@ -42,7 +42,7 @@ module Mongoid
|
|
42
42
|
#
|
43
43
|
# @param [ Object ] other The object to check.
|
44
44
|
#
|
45
|
-
# @return [ true
|
45
|
+
# @return [ true | false ] If the objects are equal in a case.
|
46
46
|
def ===(other)
|
47
47
|
return false unless other.respond_to?(:entries)
|
48
48
|
if Mongoid.legacy_triple_equals
|
@@ -192,7 +192,7 @@ module Mongoid
|
|
192
192
|
# @example Is the enumerable empty?
|
193
193
|
# enumerable.empty?
|
194
194
|
#
|
195
|
-
# @return [ true
|
195
|
+
# @return [ true | false ] If the enumerable is empty.
|
196
196
|
def empty?
|
197
197
|
if _loaded?
|
198
198
|
in_memory.empty?
|
@@ -224,7 +224,7 @@ module Mongoid
|
|
224
224
|
# @param [ Object ] condition The condition that documents
|
225
225
|
# must satisfy. See Enumerable documentation for details.
|
226
226
|
#
|
227
|
-
# @return [ true
|
227
|
+
# @return [ true | false ] If the association has any documents.
|
228
228
|
def any?(*args)
|
229
229
|
return super if args.any? || block_given?
|
230
230
|
|
@@ -261,7 +261,7 @@ module Mongoid
|
|
261
261
|
# @example Initialize the enumerable with an array.
|
262
262
|
# Enumerable.new([ post ])
|
263
263
|
#
|
264
|
-
# @param [ Criteria
|
264
|
+
# @param [ Criteria | Array<Document> ] target The wrapped object.
|
265
265
|
def initialize(target, base = nil, association = nil)
|
266
266
|
@_base = base
|
267
267
|
@_association = association
|
@@ -283,7 +283,7 @@ module Mongoid
|
|
283
283
|
#
|
284
284
|
# @param [ Document ] doc The document to check.
|
285
285
|
#
|
286
|
-
# @return [ true
|
286
|
+
# @return [ true | false ] If the document is in the target.
|
287
287
|
def include?(doc)
|
288
288
|
return super unless _unloaded
|
289
289
|
_unloaded.where(_id: doc._id).exists? || _added.has_key?(doc._id)
|
@@ -352,7 +352,7 @@ module Mongoid
|
|
352
352
|
# @example Is the enumerable _loaded?
|
353
353
|
# enumerable._loaded?
|
354
354
|
#
|
355
|
-
# @return [ true
|
355
|
+
# @return [ true | false ] If the enumerable has been _loaded.
|
356
356
|
def _loaded?
|
357
357
|
!!@executed
|
358
358
|
end
|
@@ -405,11 +405,11 @@ module Mongoid
|
|
405
405
|
# @example Does the enumerable respond to the method?
|
406
406
|
# enumerable.respond_to?(:sum)
|
407
407
|
#
|
408
|
-
# @param [ String
|
409
|
-
# @param [ true
|
408
|
+
# @param [ String | Symbol ] name The name of the method.
|
409
|
+
# @param [ true | false ] include_private Whether to include private
|
410
410
|
# methods.
|
411
411
|
#
|
412
|
-
# @return [ true
|
412
|
+
# @return [ true | false ] Whether the enumerable responds.
|
413
413
|
def respond_to?(name, include_private = false)
|
414
414
|
[].respond_to?(name, include_private) || super
|
415
415
|
end
|
@@ -25,7 +25,7 @@ module Mongoid
|
|
25
25
|
# @example Concat with other documents.
|
26
26
|
# person.posts.concat([ post_one, post_two ])
|
27
27
|
#
|
28
|
-
# @param [ Document
|
28
|
+
# @param [ Document | Array<Document> ] args Any number of documents.
|
29
29
|
#
|
30
30
|
# @return [ Array<Document> ] The loaded docs.
|
31
31
|
def <<(*args)
|
@@ -168,7 +168,7 @@ module Mongoid
|
|
168
168
|
# @example Are there persisted documents?
|
169
169
|
# person.posts.exists?
|
170
170
|
#
|
171
|
-
# @return [ true
|
171
|
+
# @return [ true | false ] True is persisted documents exist, false if not.
|
172
172
|
def exists?
|
173
173
|
criteria.exists?
|
174
174
|
end
|
@@ -184,6 +184,9 @@ module Mongoid
|
|
184
184
|
# of those found by the current Criteria object for which the block
|
185
185
|
# returns a truthy value.
|
186
186
|
#
|
187
|
+
# @note Each argument can be an individual id, an array of ids or
|
188
|
+
# a nested array. Each array will be flattened.
|
189
|
+
#
|
187
190
|
# @example Find by an id.
|
188
191
|
# person.posts.find(BSON::ObjectId.new)
|
189
192
|
#
|
@@ -196,7 +199,7 @@ module Mongoid
|
|
196
199
|
# @note This will keep matching documents in memory for iteration
|
197
200
|
# later.
|
198
201
|
#
|
199
|
-
# @param [
|
202
|
+
# @param [ Object | Array<Object> ] *args The ids.
|
200
203
|
# @param [ Proc ] block Optional block to pass.
|
201
204
|
#
|
202
205
|
# @return [ Document | Array<Document> | nil ] A document or matching documents.
|
@@ -328,7 +331,7 @@ module Mongoid
|
|
328
331
|
# relation.with_add_callbacks(document, false)
|
329
332
|
#
|
330
333
|
# @param [ Document ] document The document to append to the target.
|
331
|
-
# @param [ true
|
334
|
+
# @param [ true | false ] already_related Whether the document is already related
|
332
335
|
# to the target.
|
333
336
|
def with_add_callbacks(document, already_related)
|
334
337
|
execute_callback :before_add, document unless already_related
|
@@ -343,7 +346,7 @@ module Mongoid
|
|
343
346
|
#
|
344
347
|
# @param [ Document ] document The document to possibly append to the target.
|
345
348
|
#
|
346
|
-
# @return [ true
|
349
|
+
# @return [ true | false ] Whether the document is already related to the base and the
|
347
350
|
# association is persisted.
|
348
351
|
def already_related?(document)
|
349
352
|
document.persisted? &&
|
@@ -391,7 +394,7 @@ module Mongoid
|
|
391
394
|
#
|
392
395
|
# @param [ Document ] document The document to cascade on.
|
393
396
|
#
|
394
|
-
# @return [ true
|
397
|
+
# @return [ true | false ] If the association is destructive.
|
395
398
|
def cascade!(document)
|
396
399
|
if persistable?
|
397
400
|
case _association.dependent
|
@@ -410,11 +413,11 @@ module Mongoid
|
|
410
413
|
#
|
411
414
|
# If the method exists on the array, use the default proxy behavior.
|
412
415
|
#
|
413
|
-
# @param [ Symbol
|
416
|
+
# @param [ Symbol | String ] name The name of the method.
|
414
417
|
# @param [ Array ] args The method args
|
415
418
|
# @param [ Proc ] block Optional block to pass.
|
416
419
|
#
|
417
|
-
# @return [ Criteria
|
420
|
+
# @return [ Criteria | Object ] A Criteria or return value from the target.
|
418
421
|
ruby2_keywords def method_missing(name, *args, &block)
|
419
422
|
if _target.respond_to?(name)
|
420
423
|
_target.send(name, *args, &block)
|
@@ -450,7 +453,7 @@ module Mongoid
|
|
450
453
|
# @example Can we persist the association?
|
451
454
|
# relation.persistable?
|
452
455
|
#
|
453
|
-
# @return [ true
|
456
|
+
# @return [ true | false ] If the association is persistable.
|
454
457
|
def persistable?
|
455
458
|
!_binding? && (_creating? || _base.persisted? && !_building?)
|
456
459
|
end
|
@@ -118,7 +118,7 @@ module Mongoid
|
|
118
118
|
#
|
119
119
|
# @note Only relevant for polymorphic associations.
|
120
120
|
#
|
121
|
-
# @return [ String
|
121
|
+
# @return [ String | nil ] The type field.
|
122
122
|
def type
|
123
123
|
@type ||= "#{as}_type" if polymorphic?
|
124
124
|
end
|
@@ -140,7 +140,7 @@ module Mongoid
|
|
140
140
|
|
141
141
|
# Is this association polymorphic?
|
142
142
|
#
|
143
|
-
# @return [ true
|
143
|
+
# @return [ true | false ] Whether this association is polymorphic.
|
144
144
|
def polymorphic?
|
145
145
|
@polymorphic ||= !!as
|
146
146
|
end
|
@@ -150,7 +150,7 @@ module Mongoid
|
|
150
150
|
#
|
151
151
|
# @param [ Document ] doc The document to be bound.
|
152
152
|
#
|
153
|
-
# @return [ true
|
153
|
+
# @return [ true | false ] Whether the document can be bound.
|
154
154
|
def bindable?(doc)
|
155
155
|
forced_nil_inverse? || (!!inverse && doc.fields.keys.include?(foreign_key))
|
156
156
|
end
|
@@ -60,7 +60,7 @@ module Mongoid
|
|
60
60
|
# @example Is the id acceptable?
|
61
61
|
# one.acceptable_id?
|
62
62
|
#
|
63
|
-
# @return [ true
|
63
|
+
# @return [ true | false ] If the id part of the logic will allow an update.
|
64
64
|
def acceptable_id?
|
65
65
|
id = convert_id(existing.class, attributes[:_id])
|
66
66
|
existing._id == id || id.nil? || (existing._id != id && update_only?)
|
@@ -71,7 +71,7 @@ module Mongoid
|
|
71
71
|
# @example Can the existing object be deleted?
|
72
72
|
# one.delete?
|
73
73
|
#
|
74
|
-
# @return [ true
|
74
|
+
# @return [ true | false ] If the association should be deleted.
|
75
75
|
def delete?
|
76
76
|
destroyable? && !attributes[:_id].nil?
|
77
77
|
end
|
@@ -81,7 +81,7 @@ module Mongoid
|
|
81
81
|
# @example Is the object destroyable?
|
82
82
|
# one.destroyable?({ :_destroy => "1" })
|
83
83
|
#
|
84
|
-
# @return [ true
|
84
|
+
# @return [ true | false ] If the association can potentially be
|
85
85
|
# destroyed.
|
86
86
|
def destroyable?
|
87
87
|
[ 1, "1", true, "true" ].include?(destroy) && allow_destroy?
|
@@ -92,7 +92,7 @@ module Mongoid
|
|
92
92
|
# @example Is the document to be replaced?
|
93
93
|
# one.replace?
|
94
94
|
#
|
95
|
-
# @return [ true
|
95
|
+
# @return [ true | false ] If the document should be replaced.
|
96
96
|
def replace?
|
97
97
|
!existing && !destroyable? && !attributes.blank?
|
98
98
|
end
|
@@ -102,7 +102,7 @@ module Mongoid
|
|
102
102
|
# @example Should the document be updated?
|
103
103
|
# one.update?
|
104
104
|
#
|
105
|
-
# @return [ true
|
105
|
+
# @return [ true | false ] If the object should have its attributes updated.
|
106
106
|
def update?
|
107
107
|
existing && !destroyable? && acceptable_id?
|
108
108
|
end
|
@@ -79,7 +79,7 @@ module Mongoid
|
|
79
79
|
# @example Can we persist the association?
|
80
80
|
# relation.persistable?
|
81
81
|
#
|
82
|
-
# @return [ true
|
82
|
+
# @return [ true | false ] If the association is persistable.
|
83
83
|
def persistable?
|
84
84
|
_base.persisted? && !_binding? && !_building?
|
85
85
|
end
|
@@ -92,7 +92,7 @@ module Mongoid
|
|
92
92
|
|
93
93
|
# Is this association polymorphic?
|
94
94
|
#
|
95
|
-
# @return [ true
|
95
|
+
# @return [ true | false ] Whether this association is polymorphic.
|
96
96
|
def polymorphic?
|
97
97
|
@polymorphic ||= !!as
|
98
98
|
end
|
@@ -101,7 +101,7 @@ module Mongoid
|
|
101
101
|
#
|
102
102
|
# @note Only relevant for polymorphic associations.
|
103
103
|
#
|
104
|
-
# @return [ String
|
104
|
+
# @return [ String | nil ] The type field.
|
105
105
|
def type
|
106
106
|
@type ||= "#{as}_type" if polymorphic?
|
107
107
|
end
|
@@ -111,7 +111,7 @@ module Mongoid
|
|
111
111
|
#
|
112
112
|
# @param [ Document ] doc The document to be bound.
|
113
113
|
#
|
114
|
-
# @return [ true
|
114
|
+
# @return [ true | false ] Whether the document can be bound.
|
115
115
|
def bindable?(doc)
|
116
116
|
forced_nil_inverse? || (!!inverse && doc.fields.keys.include?(foreign_key))
|
117
117
|
end
|
@@ -16,7 +16,7 @@ module Mongoid
|
|
16
16
|
#
|
17
17
|
# @param [ Association ] association The association metadata.
|
18
18
|
#
|
19
|
-
# @return [ true
|
19
|
+
# @return [ true | false ] If we can sync.
|
20
20
|
def _syncable?(association)
|
21
21
|
!_synced?(association.foreign_key) && send(association.foreign_key_check)
|
22
22
|
end
|
@@ -38,7 +38,7 @@ module Mongoid
|
|
38
38
|
#
|
39
39
|
# @param [ String ] foreign_key The foreign key.
|
40
40
|
#
|
41
|
-
# @return [ true
|
41
|
+
# @return [ true | false ] If we can sync.
|
42
42
|
def _synced?(foreign_key)
|
43
43
|
!!_synced[foreign_key]
|
44
44
|
end
|
@@ -13,7 +13,7 @@ module Mongoid
|
|
13
13
|
# @example Find association metadata by name.
|
14
14
|
# person.reflect_on_association(:addresses)
|
15
15
|
#
|
16
|
-
# @param [ String
|
16
|
+
# @param [ String | Symbol ] name The name of the association to find.
|
17
17
|
#
|
18
18
|
# @return [ Association ] The matching association metadata.
|
19
19
|
def reflect_on_association(name)
|
@@ -39,7 +39,7 @@ module Mongoid
|
|
39
39
|
# @example Find association metadata by name.
|
40
40
|
# Person.reflect_on_association(:addresses)
|
41
41
|
#
|
42
|
-
# @param [ String
|
42
|
+
# @param [ String | Symbol ] name The name of the association to find.
|
43
43
|
#
|
44
44
|
# @return [ Association ] The matching association metadata.
|
45
45
|
def reflect_on_association(name)
|
@@ -69,7 +69,7 @@ module Mongoid
|
|
69
69
|
#
|
70
70
|
# @param [ Symbol ] callback_type The type of callback type.
|
71
71
|
#
|
72
|
-
# @return [ Array<Proc
|
72
|
+
# @return [ Array<Proc | Symbol> ] A list of the callbacks, either method
|
73
73
|
# names or Procs.
|
74
74
|
def get_callbacks(callback_type)
|
75
75
|
Array(options[callback_type])
|
@@ -88,7 +88,7 @@ module Mongoid
|
|
88
88
|
#
|
89
89
|
# @param [ Document ] doc The document to be bound.
|
90
90
|
#
|
91
|
-
# @return [ true
|
91
|
+
# @return [ true | false ] Whether the document can be bound.
|
92
92
|
def bindable?(doc); false; end
|
93
93
|
|
94
94
|
# Get the inverse names.
|
@@ -189,7 +189,7 @@ module Mongoid
|
|
189
189
|
# The foreign key field if this association stores a foreign key.
|
190
190
|
# Otherwise, the primary key.
|
191
191
|
#
|
192
|
-
# @return [ Symbol
|
192
|
+
# @return [ Symbol | String ] The primary key.
|
193
193
|
def key
|
194
194
|
stores_foreign_key? ? foreign_key : primary_key
|
195
195
|
end
|
@@ -248,7 +248,7 @@ module Mongoid
|
|
248
248
|
# Create an association proxy object using the owner and target.
|
249
249
|
#
|
250
250
|
# @param [ Document ] owner The document this association hangs off of.
|
251
|
-
# @param [ Document
|
251
|
+
# @param [ Document | Array<Document> ] target The target (parent) of the
|
252
252
|
# association.
|
253
253
|
#
|
254
254
|
# @return [ Proxy ]
|
@@ -258,7 +258,7 @@ module Mongoid
|
|
258
258
|
|
259
259
|
# Whether the dependent method is destructive.
|
260
260
|
#
|
261
|
-
# @return [ true
|
261
|
+
# @return [ true | false ] If the dependent method is destructive.
|
262
262
|
def destructive?
|
263
263
|
@destructive ||= !!(dependent && (dependent == :delete_all || dependent == :destroy))
|
264
264
|
end
|
@@ -289,7 +289,7 @@ module Mongoid
|
|
289
289
|
|
290
290
|
# Whether the associated object(s) should be validated.
|
291
291
|
#
|
292
|
-
# @return [ true
|
292
|
+
# @return [ true | false ] If the associated object(s)
|
293
293
|
# should be validated.
|
294
294
|
def validate?
|
295
295
|
@validate ||= if @options[:validate].nil?
|
data/lib/mongoid/association.rb
CHANGED
@@ -56,7 +56,7 @@ module Mongoid
|
|
56
56
|
# @example Is the document embedded?
|
57
57
|
# address.embedded?
|
58
58
|
#
|
59
|
-
# @return [ true
|
59
|
+
# @return [ true | false ] True if the document has a parent document.
|
60
60
|
def embedded?
|
61
61
|
@embedded ||= (cyclic ? _parent.present? : self.class.embedded?)
|
62
62
|
end
|
@@ -66,7 +66,7 @@ module Mongoid
|
|
66
66
|
# @example Is the document in an embeds many?
|
67
67
|
# address.embedded_many?
|
68
68
|
#
|
69
|
-
# @return [ true
|
69
|
+
# @return [ true | false ] True if in an embeds many.
|
70
70
|
def embedded_many?
|
71
71
|
_association && _association.is_a?(Association::Embedded::EmbedsMany)
|
72
72
|
end
|
@@ -76,7 +76,7 @@ module Mongoid
|
|
76
76
|
# @example Is the document in an embeds one?
|
77
77
|
# address.embedded_one?
|
78
78
|
#
|
79
|
-
# @return [ true
|
79
|
+
# @return [ true | false ] True if in an embeds one.
|
80
80
|
def embedded_one?
|
81
81
|
_association && _association.is_a?(Association::Embedded::EmbedsOne)
|
82
82
|
end
|
@@ -100,7 +100,7 @@ module Mongoid
|
|
100
100
|
# @example Is the document in a references many?
|
101
101
|
# post.referenced_many?
|
102
102
|
#
|
103
|
-
# @return [ true
|
103
|
+
# @return [ true | false ] True if in a references many.
|
104
104
|
def referenced_many?
|
105
105
|
_association && _association.is_a?(Association::Referenced::HasMany)
|
106
106
|
end
|
@@ -110,7 +110,7 @@ module Mongoid
|
|
110
110
|
# @example Is the document in a references one?
|
111
111
|
# address.referenced_one?
|
112
112
|
#
|
113
|
-
# @return [ true
|
113
|
+
# @return [ true | false ] True if in a references one.
|
114
114
|
def referenced_one?
|
115
115
|
_association && _association.is_a?(Association::Referenced::HasOne)
|
116
116
|
end
|
@@ -153,7 +153,7 @@ module Mongoid
|
|
153
153
|
#
|
154
154
|
# @param [ String ] field The field.
|
155
155
|
#
|
156
|
-
# @return [ true
|
156
|
+
# @return [ true | false ] If this field is a conflict.
|
157
157
|
def set_conflict?(field)
|
158
158
|
name = field.split(".", 2)[0]
|
159
159
|
pull_fields.has_key?(name) || push_fields.has_key?(name)
|
@@ -166,7 +166,7 @@ module Mongoid
|
|
166
166
|
#
|
167
167
|
# @param [ String ] field The field.
|
168
168
|
#
|
169
|
-
# @return [ true
|
169
|
+
# @return [ true | false ] If this field is a conflict.
|
170
170
|
def push_conflict?(field)
|
171
171
|
name = field.split(".", 2)[0]
|
172
172
|
set_fields.has_key?(name) || pull_fields.has_key?(name) ||
|
@@ -13,9 +13,9 @@ module Mongoid
|
|
13
13
|
# person.respond_to?(:title)
|
14
14
|
#
|
15
15
|
# @param [ Array ] name The name of the method.
|
16
|
-
# @param [ true
|
16
|
+
# @param [ true | false ] include_private
|
17
17
|
#
|
18
|
-
# @return [ true
|
18
|
+
# @return [ true | false ] True if it does, false if not.
|
19
19
|
def respond_to?(name, include_private = false)
|
20
20
|
super || (
|
21
21
|
attributes &&
|
@@ -114,7 +114,7 @@ module Mongoid
|
|
114
114
|
# @example Call through method_missing.
|
115
115
|
# document.method_missing(:test)
|
116
116
|
#
|
117
|
-
# @param [ String
|
117
|
+
# @param [ String | Symbol ] name The name of the method.
|
118
118
|
# @param [ Array ] args The arguments to the method.
|
119
119
|
#
|
120
120
|
# @return [ Object ] The result of the method call.
|
@@ -33,15 +33,15 @@ module Mongoid
|
|
33
33
|
# accepts_nested_attributes_for :addresses, :game, :posts
|
34
34
|
# end
|
35
35
|
#
|
36
|
-
# @param [ Array<Symbol
|
36
|
+
# @param [ Array<Symbol> | Hash ] args A list of association names, followed
|
37
37
|
# by a hash of options.
|
38
38
|
#
|
39
|
-
# @option *args [ true
|
40
|
-
# @option *args [ Proc
|
39
|
+
# @option *args [ true | false ] :allow_destroy Can deletion occur?
|
40
|
+
# @option *args [ Proc | Symbol ] :reject_if Block or symbol pointing
|
41
41
|
# to a class method to reject documents with.
|
42
42
|
# @option *args [ Integer ] :limit The max number to create.
|
43
|
-
# @option *args [ true
|
44
|
-
# @
|
43
|
+
# @option *args [ true | false ] :update_only Only update existing docs.
|
44
|
+
# @option *args [ true | false ] :autosave Whether autosave should be enabled on the
|
45
45
|
# association. Note that since the default is true, setting autosave to nil will still
|
46
46
|
# enable it.
|
47
47
|
def accepts_nested_attributes_for(*args)
|
@@ -40,7 +40,7 @@ module Mongoid
|
|
40
40
|
# @param [ Symbol ] key The name of the attribute.
|
41
41
|
# @param [ Object ] value The value of the attribute.
|
42
42
|
#
|
43
|
-
# @return [ true
|
43
|
+
# @return [ true | false ] True if pending, false if not.
|
44
44
|
def pending_attribute?(key, value)
|
45
45
|
name = key.to_s
|
46
46
|
|
@@ -41,7 +41,7 @@ module Mongoid
|
|
41
41
|
#
|
42
42
|
# @param [ String ] name The name of the attribute or a dot notation path.
|
43
43
|
#
|
44
|
-
# @return [ true
|
44
|
+
# @return [ true | false ] Whether the attribute is allowed by projection.
|
45
45
|
#
|
46
46
|
# @api private
|
47
47
|
def attribute_or_path_allowed?(name)
|
@@ -17,9 +17,9 @@ module Mongoid
|
|
17
17
|
# @example Can we write the attribute?
|
18
18
|
# model.attribute_writable?(:title)
|
19
19
|
#
|
20
|
-
# @param [ String
|
20
|
+
# @param [ String | Symbol ] name The name of the field.
|
21
21
|
#
|
22
|
-
# @return [ true
|
22
|
+
# @return [ true | false ] If the document is new, or if the field is not
|
23
23
|
# readonly.
|
24
24
|
def attribute_writable?(name)
|
25
25
|
new_record? || (!readonly_attributes.include?(name) && _loaded?(name))
|