mongoid 4.0.2 → 5.0.0.beta
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -1
- data/README.md +14 -13
- data/lib/config/locales/en.yml +28 -28
- data/lib/mongoid.rb +28 -21
- data/lib/mongoid/atomic.rb +2 -4
- data/lib/mongoid/attributes.rb +7 -7
- data/lib/mongoid/attributes/processing.rb +4 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/changeable.rb +4 -6
- data/lib/mongoid/clients.rb +142 -0
- data/lib/mongoid/clients/factory.rb +78 -0
- data/lib/mongoid/{sessions → clients}/options.rb +30 -19
- data/lib/mongoid/{sessions → clients}/storage_options.rb +27 -13
- data/lib/mongoid/{sessions → clients}/thread_options.rb +6 -3
- data/lib/mongoid/clients/validators.rb +2 -0
- data/lib/mongoid/{sessions → clients}/validators/storage.rb +5 -2
- data/lib/mongoid/composable.rb +3 -3
- data/lib/mongoid/config.rb +39 -41
- data/lib/mongoid/config/environment.rb +1 -1
- data/lib/mongoid/config/validators.rb +1 -1
- data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +11 -11
- data/lib/mongoid/contextual/command.rb +9 -6
- data/lib/mongoid/contextual/geo_near.rb +17 -1
- data/lib/mongoid/contextual/map_reduce.rb +12 -11
- data/lib/mongoid/contextual/memory.rb +2 -5
- data/lib/mongoid/contextual/mongo.rb +92 -82
- data/lib/mongoid/contextual/none.rb +13 -0
- data/lib/mongoid/copyable.rb +6 -1
- data/lib/mongoid/criteria.rb +36 -3
- data/lib/mongoid/document.rb +3 -4
- data/lib/mongoid/errors.rb +6 -6
- data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
- data/lib/mongoid/errors/no_client_config.rb +22 -0
- data/lib/mongoid/errors/{no_session_database.rb → no_client_database.rb} +4 -4
- data/lib/mongoid/errors/{no_session_hosts.rb → no_client_hosts.rb} +4 -4
- data/lib/mongoid/errors/{no_sessions_config.rb → no_clients_config.rb} +4 -4
- data/lib/mongoid/errors/no_default_client.rb +23 -0
- data/lib/mongoid/extensions/hash.rb +5 -1
- data/lib/mongoid/extensions/object.rb +3 -2
- data/lib/mongoid/extensions/set.rb +5 -5
- data/lib/mongoid/factory.rb +4 -2
- data/lib/mongoid/fields.rb +7 -2
- data/lib/mongoid/findable.rb +4 -1
- data/lib/mongoid/indexable.rb +15 -9
- data/lib/mongoid/persistable.rb +1 -2
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +3 -3
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/poppable.rb +1 -1
- data/lib/mongoid/persistable/pullable.rb +2 -2
- data/lib/mongoid/persistable/pushable.rb +2 -2
- data/lib/mongoid/persistable/renamable.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +1 -1
- data/lib/mongoid/persistable/unsettable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/query_cache.rb +98 -104
- data/lib/mongoid/railtie.rb +1 -21
- data/lib/mongoid/railties/database.rake +1 -1
- data/lib/mongoid/relations/builders.rb +3 -1
- data/lib/mongoid/relations/counter_cache.rb +1 -1
- data/lib/mongoid/relations/embedded/batchable.rb +3 -10
- data/lib/mongoid/relations/embedded/many.rb +4 -2
- data/lib/mongoid/relations/many.rb +1 -0
- data/lib/mongoid/relations/proxy.rb +6 -6
- data/lib/mongoid/relations/referenced/many.rb +2 -1
- data/lib/mongoid/relations/targets/enumerable.rb +11 -11
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +2 -2
- data/lib/mongoid/scopable.rb +6 -17
- data/lib/mongoid/selectable.rb +1 -36
- data/lib/mongoid/serializable.rb +2 -2
- data/lib/mongoid/stateful.rb +0 -1
- data/lib/mongoid/tasks/database.rake +2 -2
- data/lib/mongoid/tasks/database.rb +23 -16
- data/lib/mongoid/threaded.rb +54 -33
- data/lib/mongoid/threaded/lifecycle.rb +21 -16
- data/lib/mongoid/traversable.rb +16 -1
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/validatable/queryable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +3 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +91 -57
- data/lib/rails/mongoid.rb +2 -2
- data/spec/app/models/audio.rb +1 -1
- data/spec/app/models/band.rb +1 -0
- data/spec/app/models/company.rb +5 -0
- data/spec/app/models/label.rb +7 -0
- data/spec/app/models/pub.rb +6 -0
- data/spec/app/models/staff.rb +7 -0
- data/spec/app/models/store_as_dup_test1.rb +5 -0
- data/spec/app/models/store_as_dup_test2.rb +5 -0
- data/spec/config/mongoid.yml +7 -25
- data/spec/mongoid/atomic/paths_spec.rb +3 -11
- data/spec/mongoid/attributes/nested_spec.rb +16 -16
- data/spec/mongoid/attributes/readonly_spec.rb +80 -18
- data/spec/mongoid/attributes_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +70 -0
- data/spec/mongoid/clients/factory_spec.rb +284 -0
- data/spec/mongoid/{sessions → clients}/options_spec.rb +4 -6
- data/spec/mongoid/clients_spec.rb +739 -0
- data/spec/mongoid/config/environment_spec.rb +14 -11
- data/spec/mongoid/config_spec.rb +33 -48
- data/spec/mongoid/contextual/atomic_spec.rb +1 -17
- data/spec/mongoid/contextual/geo_near_spec.rb +35 -0
- data/spec/mongoid/contextual/mongo_spec.rb +26 -83
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +35 -1
- data/spec/mongoid/criteria/findable_spec.rb +197 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +7 -29
- data/spec/mongoid/criteria_spec.rb +74 -91
- data/spec/mongoid/document_spec.rb +1 -1
- data/spec/mongoid/errors/{mixed_session_configuration_spec.rb → mixed_client_configuration_spec.rb} +1 -1
- data/spec/mongoid/errors/{no_session_config_spec.rb → no_client_config_spec.rb} +4 -4
- data/spec/mongoid/errors/{no_session_database_spec.rb → no_client_database_spec.rb} +4 -4
- data/spec/mongoid/errors/{no_session_hosts_spec.rb → no_client_hosts_spec.rb} +3 -3
- data/spec/mongoid/errors/{no_sessions_config_spec.rb → no_clients_config_spec.rb} +2 -2
- data/spec/mongoid/fields/localized_spec.rb +1 -0
- data/spec/mongoid/fields_spec.rb +1 -0
- data/spec/mongoid/findable_spec.rb +2 -23
- data/spec/mongoid/indexable_spec.rb +12 -8
- data/spec/mongoid/interceptable_spec.rb +15 -0
- data/spec/mongoid/persistable/settable_spec.rb +16 -0
- data/spec/mongoid/persistable/updatable_spec.rb +3 -2
- data/spec/mongoid/persistable_spec.rb +4 -4
- data/spec/mongoid/query_cache_spec.rb +13 -8
- data/spec/mongoid/relations/auto_save_spec.rb +1 -1
- data/spec/mongoid/relations/counter_cache_spec.rb +34 -0
- data/spec/mongoid/relations/eager/belongs_to_spec.rb +9 -0
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +3 -3
- data/spec/mongoid/relations/embedded/many_spec.rb +123 -1
- data/spec/mongoid/relations/embedded/one_spec.rb +3 -3
- data/spec/mongoid/relations/proxy_spec.rb +28 -0
- data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +47 -23
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
- data/spec/mongoid/relations/targets/enumerable_spec.rb +9 -2
- data/spec/mongoid/reloadable_spec.rb +6 -6
- data/spec/mongoid/scopable_spec.rb +41 -28
- data/spec/mongoid/selectable_spec.rb +6 -16
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +2 -2
- data/spec/mongoid/threaded_spec.rb +0 -7
- data/spec/mongoid/traversable_spec.rb +2 -2
- data/spec/mongoid/validatable/uniqueness_spec.rb +30 -1
- data/spec/mongoid_spec.rb +13 -15
- data/spec/rails/mongoid_spec.rb +13 -4
- data/spec/spec_helper.rb +44 -27
- data/spec/support/authorization.rb +12 -0
- data/spec/support/expectations.rb +14 -0
- metadata +52 -59
- data/lib/mongoid/contextual/find_and_modify.rb +0 -69
- data/lib/mongoid/contextual/text_search.rb +0 -178
- data/lib/mongoid/criteria/#findable.rb# +0 -141
- data/lib/mongoid/errors/no_default_session.rb +0 -23
- data/lib/mongoid/errors/no_session_config.rb +0 -22
- data/lib/mongoid/log_subscriber.rb +0 -55
- data/lib/mongoid/positional.rb +0 -71
- data/lib/mongoid/sessions.rb +0 -125
- data/lib/mongoid/sessions/factory.rb +0 -131
- data/lib/mongoid/sessions/mongo_uri.rb +0 -93
- data/lib/mongoid/sessions/validators.rb +0 -2
- data/lib/mongoid/support/query_counter.rb +0 -23
- data/spec/helpers.rb +0 -18
- data/spec/mongoid/#atomic_spec.rb# +0 -365
- data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
- data/spec/mongoid/contextual/text_search_spec.rb +0 -209
- data/spec/mongoid/log_subscriber_spec.rb +0 -75
- data/spec/mongoid/positional_spec.rb +0 -222
- data/spec/mongoid/sessions/factory_spec.rb +0 -333
- data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
- data/spec/mongoid/sessions_spec.rb +0 -1252
data/lib/mongoid/threaded.rb
CHANGED
@@ -6,10 +6,24 @@ module Mongoid
|
|
6
6
|
# This module contains logic for easy access to objects that have a lifecycle
|
7
7
|
# on the current thread.
|
8
8
|
module Threaded
|
9
|
+
|
9
10
|
DATABASE_OVERRIDE_KEY = "[mongoid]:db-override"
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
# Constant for the key to store clients.
|
13
|
+
#
|
14
|
+
# @since 5.0.0
|
15
|
+
CLIENTS_KEY = "[mongoid]:clients"
|
16
|
+
|
17
|
+
# The key to override the client.
|
18
|
+
#
|
19
|
+
# @since 5.0.0
|
20
|
+
CLIENT_OVERRIDE_KEY = "[mongoid]:client-override"
|
21
|
+
|
22
|
+
# The key for the current thread's scope stack.
|
23
|
+
#
|
24
|
+
# @since 2.0.0
|
25
|
+
CURRENT_SCOPE_KEY = "[mongoid]:current-scope"
|
26
|
+
|
13
27
|
AUTOSAVES_KEY = "[mongoid]:autosaves"
|
14
28
|
VALIDATIONS_KEY = "[mongoid]:validations"
|
15
29
|
|
@@ -17,6 +31,7 @@ module Mongoid
|
|
17
31
|
hash[key] = "[mongoid]:#{key}-stack"
|
18
32
|
end
|
19
33
|
|
34
|
+
extend Gem::Deprecate
|
20
35
|
extend self
|
21
36
|
|
22
37
|
# Begin entry into a named thread local stack.
|
@@ -59,18 +74,6 @@ module Mongoid
|
|
59
74
|
Thread.current[DATABASE_OVERRIDE_KEY] = name
|
60
75
|
end
|
61
76
|
|
62
|
-
# Get the database sessions from the current thread.
|
63
|
-
#
|
64
|
-
# @example Get the database sessions.
|
65
|
-
# Threaded.sessions
|
66
|
-
#
|
67
|
-
# @return [ Hash ] The sessions.
|
68
|
-
#
|
69
|
-
# @since 3.0.0
|
70
|
-
def sessions
|
71
|
-
Thread.current[SESSIONS_KEY] ||= {}
|
72
|
-
end
|
73
|
-
|
74
77
|
# Are in the middle of executing the named stack
|
75
78
|
#
|
76
79
|
# @example Are we in the stack execution?
|
@@ -161,42 +164,60 @@ module Mongoid
|
|
161
164
|
validations_for(document.class).delete_one(document._id)
|
162
165
|
end
|
163
166
|
|
164
|
-
# Get the global
|
167
|
+
# Get the global client override.
|
165
168
|
#
|
166
|
-
# @example Get the global
|
167
|
-
# Threaded.
|
169
|
+
# @example Get the global client override.
|
170
|
+
# Threaded.client_override
|
168
171
|
#
|
169
172
|
# @return [ String, Symbol ] The override.
|
170
173
|
#
|
171
|
-
# @since
|
172
|
-
def
|
173
|
-
Thread.current[
|
174
|
+
# @since 5.0.0
|
175
|
+
def client_override
|
176
|
+
Thread.current[CLIENT_OVERRIDE_KEY]
|
174
177
|
end
|
178
|
+
alias :session_override :client_override
|
179
|
+
deprecate :session_override, :client_override, 2015, 12
|
175
180
|
|
176
|
-
# Set the global
|
181
|
+
# Set the global client override.
|
177
182
|
#
|
178
|
-
# @example Set the global
|
179
|
-
# Threaded.
|
183
|
+
# @example Set the global client override.
|
184
|
+
# Threaded.client_override = :testing
|
180
185
|
#
|
181
186
|
# @param [ String, Symbol ] The global override name.
|
182
187
|
#
|
183
188
|
# @return [ String, Symbol ] The override.
|
184
189
|
#
|
185
190
|
# @since 3.0.0
|
186
|
-
def
|
187
|
-
Thread.current[
|
191
|
+
def client_override=(name)
|
192
|
+
Thread.current[CLIENT_OVERRIDE_KEY] = name
|
193
|
+
end
|
194
|
+
alias :session_override= :client_override=
|
195
|
+
deprecate :session_override=, :client_override=, 2015, 12
|
196
|
+
|
197
|
+
# Get the current Mongoid scope.
|
198
|
+
#
|
199
|
+
# @example Get the scope.
|
200
|
+
# Threaded.current_scope
|
201
|
+
#
|
202
|
+
# @return [ Criteria ] The scope.
|
203
|
+
#
|
204
|
+
# @since 5.0.0
|
205
|
+
def current_scope
|
206
|
+
Thread.current[CURRENT_SCOPE_KEY]
|
188
207
|
end
|
189
208
|
|
190
|
-
#
|
209
|
+
# Set the current Mongoid scope.
|
210
|
+
#
|
211
|
+
# @example Set the scope.
|
212
|
+
# Threaded.current_scope = scope
|
191
213
|
#
|
192
|
-
# @
|
193
|
-
# Threaded.scope_stack
|
214
|
+
# @param [ Criteria ] scope The current scope.
|
194
215
|
#
|
195
|
-
# @return [
|
216
|
+
# @return [ Criteria ] The scope.
|
196
217
|
#
|
197
|
-
# @since
|
198
|
-
def
|
199
|
-
Thread.current[
|
218
|
+
# @since 5.0.0
|
219
|
+
def current_scope=(scope)
|
220
|
+
Thread.current[CURRENT_SCOPE_KEY] = scope
|
200
221
|
end
|
201
222
|
|
202
223
|
# Is the document autosaved on the current thread?
|
@@ -1,7 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid
|
3
3
|
module Threaded
|
4
|
-
|
4
|
+
BIND = 'bind'.freeze
|
5
|
+
ASSIGN = 'assign'.freeze
|
6
|
+
BUILD = 'build'.freeze
|
7
|
+
LOAD = 'load'.freeze
|
8
|
+
CREATE = 'create'.freeze
|
9
|
+
|
5
10
|
# This module contains convenience methods for document lifecycle that
|
6
11
|
# resides on thread locals.
|
7
12
|
module Lifecycle
|
@@ -22,10 +27,10 @@ module Mongoid
|
|
22
27
|
#
|
23
28
|
# @since 2.2.0
|
24
29
|
def _assigning
|
25
|
-
Threaded.begin_execution(
|
30
|
+
Threaded.begin_execution(ASSIGN)
|
26
31
|
yield
|
27
32
|
ensure
|
28
|
-
Threaded.exit_execution(
|
33
|
+
Threaded.exit_execution(ASSIGN)
|
29
34
|
end
|
30
35
|
|
31
36
|
# Is the current thread in assigning mode?
|
@@ -37,7 +42,7 @@ module Mongoid
|
|
37
42
|
#
|
38
43
|
# @since 2.1.0
|
39
44
|
def _assigning?
|
40
|
-
Threaded.executing?(
|
45
|
+
Threaded.executing?(ASSIGN)
|
41
46
|
end
|
42
47
|
|
43
48
|
# Execute a block in binding mode.
|
@@ -51,10 +56,10 @@ module Mongoid
|
|
51
56
|
#
|
52
57
|
# @since 2.1.0
|
53
58
|
def _binding
|
54
|
-
Threaded.begin_execution(
|
59
|
+
Threaded.begin_execution(BIND)
|
55
60
|
yield
|
56
61
|
ensure
|
57
|
-
Threaded.exit_execution(
|
62
|
+
Threaded.exit_execution(BIND)
|
58
63
|
end
|
59
64
|
|
60
65
|
# Is the current thread in binding mode?
|
@@ -66,7 +71,7 @@ module Mongoid
|
|
66
71
|
#
|
67
72
|
# @since 2.1.0
|
68
73
|
def _binding?
|
69
|
-
Threaded.executing?(
|
74
|
+
Threaded.executing?(BIND)
|
70
75
|
end
|
71
76
|
|
72
77
|
# Execute a block in building mode.
|
@@ -80,10 +85,10 @@ module Mongoid
|
|
80
85
|
#
|
81
86
|
# @since 2.1.0
|
82
87
|
def _building
|
83
|
-
Threaded.begin_execution(
|
88
|
+
Threaded.begin_execution(BUILD)
|
84
89
|
yield
|
85
90
|
ensure
|
86
|
-
Threaded.exit_execution(
|
91
|
+
Threaded.exit_execution(BUILD)
|
87
92
|
end
|
88
93
|
|
89
94
|
# Is the current thread in building mode?
|
@@ -95,7 +100,7 @@ module Mongoid
|
|
95
100
|
#
|
96
101
|
# @since 2.1.0
|
97
102
|
def _building?
|
98
|
-
Threaded.executing?(
|
103
|
+
Threaded.executing?(BUILD)
|
99
104
|
end
|
100
105
|
|
101
106
|
# Is the current thread in creating mode?
|
@@ -107,7 +112,7 @@ module Mongoid
|
|
107
112
|
#
|
108
113
|
# @since 2.1.0
|
109
114
|
def _creating?
|
110
|
-
Threaded.executing?(
|
115
|
+
Threaded.executing?(CREATE)
|
111
116
|
end
|
112
117
|
|
113
118
|
# Execute a block in loading mode.
|
@@ -121,10 +126,10 @@ module Mongoid
|
|
121
126
|
#
|
122
127
|
# @since 2.3.2
|
123
128
|
def _loading
|
124
|
-
Threaded.begin_execution(
|
129
|
+
Threaded.begin_execution(LOAD)
|
125
130
|
yield
|
126
131
|
ensure
|
127
|
-
Threaded.exit_execution(
|
132
|
+
Threaded.exit_execution(LOAD)
|
128
133
|
end
|
129
134
|
|
130
135
|
# Is the current thread in loading mode?
|
@@ -136,7 +141,7 @@ module Mongoid
|
|
136
141
|
#
|
137
142
|
# @since 2.3.2
|
138
143
|
def _loading?
|
139
|
-
Threaded.executing?(
|
144
|
+
Threaded.executing?(LOAD)
|
140
145
|
end
|
141
146
|
|
142
147
|
module ClassMethods
|
@@ -152,10 +157,10 @@ module Mongoid
|
|
152
157
|
#
|
153
158
|
# @since 2.1.0
|
154
159
|
def _creating
|
155
|
-
Threaded.begin_execution(
|
160
|
+
Threaded.begin_execution(CREATE)
|
156
161
|
yield
|
157
162
|
ensure
|
158
|
-
Threaded.exit_execution(
|
163
|
+
Threaded.exit_execution(CREATE)
|
159
164
|
end
|
160
165
|
|
161
166
|
end
|
data/lib/mongoid/traversable.rb
CHANGED
@@ -124,6 +124,21 @@ module Mongoid
|
|
124
124
|
child.move_changes
|
125
125
|
child.new_record = false
|
126
126
|
end
|
127
|
+
_reset_memoized_children!
|
128
|
+
end
|
129
|
+
|
130
|
+
# Resets the memoized children on the object. Called internally when an
|
131
|
+
# embedded array changes size.
|
132
|
+
#
|
133
|
+
# @api semiprivate
|
134
|
+
#
|
135
|
+
# @example Reset the memoized children.
|
136
|
+
# document._reset_memoized_children!
|
137
|
+
#
|
138
|
+
# @return [ nil ] nil.
|
139
|
+
#
|
140
|
+
# @since 5.0.0
|
141
|
+
def _reset_memoized_children!
|
127
142
|
@__children = nil
|
128
143
|
end
|
129
144
|
|
@@ -161,7 +176,7 @@ module Mongoid
|
|
161
176
|
#
|
162
177
|
# @return [ true, false ] True if hereditary, false if not.
|
163
178
|
def hereditary?
|
164
|
-
Mongoid::Document > superclass
|
179
|
+
!!(Mongoid::Document > superclass)
|
165
180
|
end
|
166
181
|
|
167
182
|
# When inheriting, we want to copy the fields from the parent class and
|
data/lib/mongoid/validatable.rb
CHANGED
@@ -68,7 +68,7 @@ module Mongoid
|
|
68
68
|
# @since 2.0.0.rc.1
|
69
69
|
def read_attribute_for_validation(attr)
|
70
70
|
attribute = database_field_name(attr)
|
71
|
-
if relations.
|
71
|
+
if relations.key?(attribute)
|
72
72
|
begin_validate
|
73
73
|
relation = without_autobuild { send(attr) }
|
74
74
|
exit_validate
|
@@ -4,7 +4,7 @@ module Mongoid
|
|
4
4
|
module Queryable
|
5
5
|
|
6
6
|
# Wrap the validation inside the an execution block that alert's the
|
7
|
-
#
|
7
|
+
# client not to clear its persistence options.
|
8
8
|
#
|
9
9
|
# @example Execute the validation with a query.
|
10
10
|
# with_query(document) do
|
@@ -122,8 +122,8 @@ module Mongoid
|
|
122
122
|
def criterion(document, attribute, value)
|
123
123
|
field = document.database_field_name(attribute)
|
124
124
|
|
125
|
-
if localized?(document, field)
|
126
|
-
conditions = value.inject([]) { |acc, (k,v)| acc << { "#{field}.#{k}" => filter(v) }
|
125
|
+
if value && localized?(document, field)
|
126
|
+
conditions = (value || {}).inject([]) { |acc, (k,v)| acc << { "#{field}.#{k}" => filter(v) }}
|
127
127
|
selector = { "$or" => conditions }
|
128
128
|
else
|
129
129
|
selector = { field => filter(value) }
|
@@ -274,7 +274,7 @@ module Mongoid
|
|
274
274
|
criteria = create_criteria(klass, document, attribute, value)
|
275
275
|
criteria = criteria.merge(options[:conditions].call) if options[:conditions]
|
276
276
|
|
277
|
-
if criteria.with(persistence_options(
|
277
|
+
if criteria.with(criteria.persistence_options).read(mode: :primary).exists?
|
278
278
|
add_error(document, attribute, value)
|
279
279
|
end
|
280
280
|
end
|
@@ -296,23 +296,6 @@ module Mongoid
|
|
296
296
|
scope_value_changed?(document)
|
297
297
|
end
|
298
298
|
|
299
|
-
# Get the persistence options to perform to check, merging with any
|
300
|
-
# existing.
|
301
|
-
#
|
302
|
-
# @api private
|
303
|
-
#
|
304
|
-
# @example Get the persistence options.
|
305
|
-
# validator.persistence_options(criteria)
|
306
|
-
#
|
307
|
-
# @param [ Criteria ] criteria The criteria.
|
308
|
-
#
|
309
|
-
# @return [ Hash ] The persistence options.
|
310
|
-
#
|
311
|
-
# @since 3.0.23
|
312
|
-
def persistence_options(criteria)
|
313
|
-
(criteria.persistence_options || {}).merge!(read: :primary)
|
314
|
-
end
|
315
|
-
|
316
299
|
# Is the attribute localized?
|
317
300
|
#
|
318
301
|
# @api private
|
data/lib/mongoid/version.rb
CHANGED
@@ -1,62 +1,101 @@
|
|
1
1
|
development:
|
2
|
-
# Configure available database
|
3
|
-
|
4
|
-
# Defines the default
|
2
|
+
# Configure available database clients. (required)
|
3
|
+
clients:
|
4
|
+
# Defines the default client. (required)
|
5
5
|
default:
|
6
6
|
# Defines the name of the default database that Mongoid can connect to.
|
7
7
|
# (required).
|
8
8
|
database: <%= database_name || app_name %>_development
|
9
|
-
# Provides the hosts the default
|
9
|
+
# Provides the hosts the default client can connect to. Must be an array
|
10
10
|
# of host:port pairs. (required)
|
11
11
|
hosts:
|
12
12
|
- localhost:27017
|
13
13
|
options:
|
14
14
|
# Change the default write concern. (default = { w: 1 })
|
15
15
|
# write:
|
16
|
-
#
|
17
|
-
|
18
|
-
# Change the default
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# read:
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
# The
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
39
|
-
# (default:
|
40
|
-
#
|
41
|
-
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
# (default:
|
52
|
-
#
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
#
|
58
|
-
#
|
59
|
-
|
16
|
+
# w: 1
|
17
|
+
|
18
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
19
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
20
|
+
# (default: primary)
|
21
|
+
# read:
|
22
|
+
# mode: :secondary_preferred
|
23
|
+
|
24
|
+
# The name of the user for authentication.
|
25
|
+
# user: 'user'
|
26
|
+
|
27
|
+
# The password of the user for authentication.
|
28
|
+
# password: 'password'
|
29
|
+
|
30
|
+
# The user's database roles.
|
31
|
+
# roles:
|
32
|
+
# - 'dbOwner'
|
33
|
+
|
34
|
+
# Change the default authentication mechanism. Valid options are: :scram,
|
35
|
+
# :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default
|
36
|
+
# on 2.4 and 2.6 is :plain)
|
37
|
+
# auth_mech: :scram
|
38
|
+
|
39
|
+
# The database or source to authenticate the user against. (default: admin)
|
40
|
+
# auth_source: admin
|
41
|
+
|
42
|
+
# Force a the driver cluster to behave in a certain manner instead of auto-
|
43
|
+
# discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
44
|
+
# when connecting to hidden members of a replica set.
|
45
|
+
# connect: :direct
|
46
|
+
|
47
|
+
# Changes the default time in seconds the server monitors refresh their status
|
48
|
+
# via ismaster commands. (default: 10)
|
49
|
+
# heartbeat_frequency: 10
|
50
|
+
|
51
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
52
|
+
# local_threshold: 5
|
53
|
+
|
54
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
55
|
+
# server_selection_timeout: 30
|
56
|
+
|
57
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
58
|
+
# max_pool_size: 5
|
59
|
+
|
60
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
61
|
+
# min_pool_size: 1
|
62
|
+
|
63
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
64
|
+
# to be checked in before timing out. (default: 5)
|
65
|
+
# wait_queue_timeout: 5
|
66
|
+
|
67
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
68
|
+
# (default: 5)
|
69
|
+
# connect_timeout: 5
|
70
|
+
|
71
|
+
# The timeout to wait to execute operations on a socket before raising an error.
|
72
|
+
# (default: 5)
|
73
|
+
# socket_timeout: 5
|
74
|
+
|
75
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
76
|
+
# not belong to this replica set will be ignored.
|
77
|
+
# replica_set: name
|
78
|
+
|
79
|
+
# Whether to connect to the servers via ssl. (default: false)
|
80
|
+
# ssl: true
|
81
|
+
|
82
|
+
# The certificate file used to identify the connection against MongoDB.
|
83
|
+
# ssl_cert: /path/to/my.cert
|
84
|
+
|
85
|
+
# The private keyfile used to identify the connection against MongoDB.
|
86
|
+
# Note that even if the key is stored in the same file as the certificate,
|
87
|
+
# both need to be explicitly specified.
|
88
|
+
# ssl_key: /path/to/my.key
|
89
|
+
|
90
|
+
# A passphrase for the private key.
|
91
|
+
# ssl_key_pass_phrase: password
|
92
|
+
|
93
|
+
# Whether or not to do peer certification validation. (default: false)
|
94
|
+
# ssl_verify: true
|
95
|
+
|
96
|
+
# The file containing a set of concatenated certification authority certifications
|
97
|
+
# used to validate certs passed from the other end of the connection.
|
98
|
+
# ssl_ca_cert: /path/to/ca.cert
|
60
99
|
|
61
100
|
|
62
101
|
# Configure Mongoid specific options. (optional)
|
@@ -71,9 +110,6 @@ development:
|
|
71
110
|
# inheritance. (default: false)
|
72
111
|
# preload_models: false
|
73
112
|
|
74
|
-
# Protect id and type from mass assignment. (default: true)
|
75
|
-
# protect_sensitive_fields: true
|
76
|
-
|
77
113
|
# Raise an error when performing a #find and the document is not found.
|
78
114
|
# (default: true)
|
79
115
|
# raise_not_found_error: true
|
@@ -88,14 +124,12 @@ development:
|
|
88
124
|
# Ensure all times are UTC in the app side. (default: false)
|
89
125
|
# use_utc: false
|
90
126
|
test:
|
91
|
-
|
127
|
+
clients:
|
92
128
|
default:
|
93
129
|
database: <%= database_name || app_name %>_test
|
94
130
|
hosts:
|
95
131
|
- localhost:27017
|
96
132
|
options:
|
97
|
-
read:
|
98
|
-
|
99
|
-
|
100
|
-
max_retries: 1
|
101
|
-
retry_interval: 0
|
133
|
+
read:
|
134
|
+
mode: primary
|
135
|
+
max_pool_size: 1
|