Skip to content

Commit 1eaabc2

Browse files
Merge branch 'master' into docs-full-namespaces
2 parents ea217ed + a5e5cd6 commit 1eaabc2

37 files changed

+932
-355
lines changed

.github/workflows/test.yml

Lines changed: 43 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
include:
21-
- mongodb: '5.0'
21+
- mongodb: '6.0'
2222
ruby: ruby-3.1
23-
topology: server
23+
topology: replica_set
2424
os: ubuntu-20.04
2525
task: test
2626
driver: current
2727
rails:
2828
i18n:
2929
gemfile: Gemfile
3030
experimental: false
31-
- mongodb: '5.0'
31+
- mongodb: '6.0'
3232
ruby: ruby-3.1
3333
topology: replica_set
3434
os: ubuntu-20.04
@@ -38,17 +38,7 @@ jobs:
3838
i18n:
3939
gemfile: Gemfile
4040
experimental: false
41-
- mongodb: '5.0'
42-
ruby: ruby-3.0
43-
topology: server
44-
os: ubuntu-20.04
45-
task: test
46-
driver: current
47-
rails:
48-
i18n:
49-
gemfile: Gemfile
50-
experimental: false
51-
- mongodb: '5.0'
41+
- mongodb: '6.0'
5242
ruby: ruby-3.0
5343
topology: replica_set
5444
os: ubuntu-20.04
@@ -58,77 +48,7 @@ jobs:
5848
i18n:
5949
gemfile: Gemfile
6050
experimental: false
61-
- mongodb: '5.0'
62-
ruby: jruby-9.3
63-
topology: replica_set
64-
os: ubuntu-20.04
65-
task: test
66-
driver: current
67-
rails:
68-
i18n:
69-
gemfile: Gemfile
70-
experimental: false
71-
- mongodb: '4.4'
72-
ruby: ruby-2.7
73-
topology: server
74-
os: ubuntu-20.04
75-
task: test
76-
driver: current
77-
rails:
78-
i18n:
79-
gemfile: Gemfile
80-
experimental: false
81-
- mongodb: '4.4'
82-
ruby: ruby-2.7
83-
topology: replica_set
84-
os: ubuntu-20.04
85-
task: test
86-
driver: current
87-
rails:
88-
i18n:
89-
gemfile: Gemfile
90-
experimental: false
91-
- mongodb: '4.0'
92-
ruby: ruby-2.6
93-
topology: server
94-
os: ubuntu-18.04
95-
task: test
96-
driver: current
97-
rails:
98-
i18n:
99-
gemfile: Gemfile
100-
experimental: false
101-
- mongodb: '4.0'
102-
ruby: ruby-2.6
103-
topology: replica_set
104-
os: ubuntu-18.04
105-
task: test
106-
driver: current
107-
rails:
108-
i18n:
109-
gemfile: Gemfile
110-
experimental: false
111-
- mongodb: '3.6'
112-
ruby: ruby-2.6
113-
topology: server
114-
os: ubuntu-18.04
115-
task: test
116-
driver: current
117-
rails:
118-
i18n:
119-
gemfile: Gemfile
120-
experimental: false
121-
- mongodb: '3.6'
122-
ruby: ruby-2.6
123-
topology: replica_set
124-
os: ubuntu-18.04
125-
task: test
126-
driver: current
127-
rails:
128-
i18n:
129-
gemfile: Gemfile
130-
experimental: false
131-
- mongodb: '5.0'
51+
- mongodb: '6.0'
13252
ruby: ruby-3.1
13353
topology: replica_set
13454
os: ubuntu-20.04
@@ -138,7 +58,7 @@ jobs:
13858
i18n:
13959
gemfile: gemfiles/driver_master.gemfile
14060
experimental: true
141-
- mongodb: '5.0'
61+
- mongodb: '6.0'
14262
ruby: ruby-3.0
14363
topology: replica_set
14464
os: ubuntu-20.04
@@ -148,37 +68,7 @@ jobs:
14868
i18n:
14969
gemfile: gemfiles/driver_stable.gemfile
15070
experimental: false
151-
- mongodb: '4.0'
152-
ruby: ruby-2.6
153-
topology: replica_set
154-
os: ubuntu-18.04
155-
task: test
156-
driver: oldstable
157-
rails:
158-
i18n:
159-
gemfile: gemfiles/driver_oldstable.gemfile
160-
experimental: false
161-
- mongodb: '4.0'
162-
ruby: ruby-2.6
163-
topology: replica_set
164-
os: ubuntu-18.04
165-
task: test
166-
driver: min
167-
rails:
168-
i18n:
169-
gemfile: gemfiles/driver_min.gemfile
170-
experimental: false
171-
- mongodb: '3.6'
172-
ruby: ruby-2.6
173-
topology: server
174-
os: ubuntu-18.04
175-
task: test
176-
driver: min
177-
rails:
178-
i18n:
179-
gemfile: gemfiles/driver_min.gemfile
180-
experimental: false
181-
- mongodb: '5.0'
71+
- mongodb: '6.0'
18272
ruby: ruby-3.1
18373
topology: server
18474
os: ubuntu-20.04
@@ -188,7 +78,7 @@ jobs:
18878
i18n:
18979
gemfile: gemfiles/rails-7.0.gemfile
19080
experimental: false
191-
- mongodb: '5.0'
81+
- mongodb: '6.0'
19282
ruby: ruby-3.1
19383
topology: server
19484
os: ubuntu-20.04
@@ -198,7 +88,7 @@ jobs:
19888
i18n:
19989
gemfile: gemfiles/rails-6.1.gemfile
20090
experimental: false
201-
- mongodb: '5.0'
91+
- mongodb: '6.0'
20292
ruby: ruby-3.0
20393
topology: server
20494
os: ubuntu-20.04
@@ -208,7 +98,7 @@ jobs:
20898
i18n:
20999
gemfile: gemfiles/rails-7.0.gemfile
210100
experimental: false
211-
- mongodb: '5.0'
101+
- mongodb: '6.0'
212102
ruby: ruby-3.0
213103
topology: server
214104
os: ubuntu-20.04
@@ -218,7 +108,7 @@ jobs:
218108
i18n:
219109
gemfile: gemfiles/rails-6.1.gemfile
220110
experimental: false
221-
- mongodb: '5.0'
111+
- mongodb: '6.0'
222112
ruby: ruby-3.0
223113
topology: server
224114
os: ubuntu-20.04
@@ -228,66 +118,69 @@ jobs:
228118
i18n:
229119
gemfile: gemfiles/rails-6.0.gemfile
230120
experimental: false
231-
- mongodb: '4.0'
121+
- mongodb: '6.0'
232122
ruby: ruby-2.7
233123
topology: server
234-
os: ubuntu-18.04
124+
os: ubuntu-20.04
235125
task: test
236126
driver: current
237127
rails: '5.2'
238128
i18n:
239129
gemfile: gemfiles/rails-5.2.gemfile
240130
experimental: false
241-
- mongodb: '4.4'
242-
ruby: ruby-2.6
131+
- mongodb: '6.0'
132+
ruby: jruby-9.3
243133
topology: server
244134
os: ubuntu-20.04
245135
task: test
246136
driver: current
247-
rails:
248-
i18n: '1.0'
249-
gemfile: gemfiles/i18n-1.0.gemfile
137+
rails: '6.0'
138+
i18n:
139+
gemfile: gemfiles/rails-6.0.gemfile
250140
experimental: false
251-
- mongodb: '4.2'
252-
ruby: ruby-2.6
253-
topology: server
254-
os: ubuntu-18.04
141+
142+
- mongodb: '5.0'
143+
ruby: ruby-3.1
144+
topology: replica_set
145+
os: ubuntu-20.04
255146
task: test
256147
driver: current
257148
rails:
258-
i18n: '1.0'
259-
gemfile: gemfiles/i18n-1.0.gemfile
149+
i18n:
150+
gemfile: Gemfile
260151
experimental: false
261-
- mongodb: '4.2'
262-
ruby: ruby-2.6
263-
topology: server
264-
os: ubuntu-18.04
152+
- mongodb: '4.4'
153+
ruby: ruby-2.7
154+
topology: replica_set
155+
os: ubuntu-20.04
265156
task: test
266157
driver: current
267158
rails:
268-
i18n: current
159+
i18n:
269160
gemfile: Gemfile
270161
experimental: false
271-
- mongodb: '5.0'
162+
- mongodb: '4.0'
272163
ruby: ruby-2.7
273-
topology: server
274-
os: ubuntu-20.04
164+
topology: replica_set
165+
os: ubuntu-18.04
275166
task: test
276167
driver: current
277-
rails: '5.2'
168+
rails:
278169
i18n:
279-
gemfile: gemfiles/rails-5.2.gemfile
170+
gemfile: Gemfile
280171
experimental: false
281-
- mongodb: '5.0'
282-
ruby: jruby-9.3
283-
topology: server
284-
os: ubuntu-20.04
172+
- mongodb: '3.6'
173+
ruby: ruby-2.7
174+
topology: replica_set
175+
os: ubuntu-18.04
285176
task: test
286177
driver: current
287-
rails: '6.0'
178+
rails:
288179
i18n:
289-
gemfile: gemfiles/rails-6.0.gemfile
180+
gemfile: Gemfile
290181
experimental: false
182+
183+
291184
steps:
292185
- name: repo checkout
293186
uses: actions/checkout@v2

docs/release-notes/mongoid-9.0.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ persistence operation per parent document, even when using multiple
191191
levels of nested embedded documents.
192192

193193

194+
``embedded_in`` associations now default to ``touch: true``
195+
-----------------------------------------------------------
196+
197+
Updating an embedded subdocument will now automatically touch the parent,
198+
unless you explicitly set ``touch: false`` on the relation:
199+
200+
.. code-block:: ruby
201+
202+
class Address
203+
include Mongoid::Document
204+
include Mongoid::Timestamps
205+
206+
embedded_in :mall, touch: false
207+
end
208+
209+
For all other associations, the default remains ``touch: false``.
210+
211+
194212
Flipped default for ``:replace`` option in ``#upsert``
195213
------------------------------------------------------
196214

@@ -204,6 +222,25 @@ This means that, by default, Mongoid 9 will update the existing document and
204222
will not replace it.
205223

206224

225+
The immutability of the ``_id`` field is now enforced
226+
-----------------------------------------------------
227+
228+
Prior to Mongoid 9.0, mutating the ``_id`` field behaved inconsistently
229+
depending on whether the document was top-level or embedded, and depending on
230+
how the update was performed. As of 9.0, changing the ``_id`` field will now
231+
raise an exception when the document is saved, if the document had been
232+
previously persisted.
233+
234+
Mongoid 9.0 also introduces a new feature flag, ``immutable_ids``, which
235+
defaults to ``true``.
236+
237+
.. code-block:: ruby
238+
239+
Mongoid::Config.immutable_ids = true
240+
241+
When set to false, the older, inconsistent behavior is restored.
242+
243+
207244
Bug Fixes and Improvements
208245
--------------------------
209246

lib/config/locales/en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ en:
119119
summary: "Your mongoid.yml configuration file appears to be empty."
120120
resolution: "Ensure your configuration file contains the correct contents.
121121
Refer to: https://www.mongodb.com/docs/mongoid/current/reference/configuration/"
122+
immutable_attribute:
123+
message: "Attempted to change the immutable attribute '%{name}' with
124+
the value: %{value}."
125+
summary: "Immutable attributes can only have values set when the
126+
document is a new record."
127+
resolution: "Do not attempt to update the value of '%{name}' after
128+
the document is persisted."
122129
invalid_collection:
123130
message: "Access to the collection for %{klass} is not allowed."
124131
summary: "%{klass}.collection was called, and %{klass} is an embedded

lib/mongoid/association/accessors.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,11 @@ def self.define_setter!(association)
341341
klass.re_define_method("#{name}=") do |object|
342342
without_autobuild do
343343
if value = get_relation(name, association, object)
344-
if value.respond_to?(:substitute)
345-
set_relation(name, value.substitute(object.substitutable))
346-
else
347-
value = __build__(name, value, association)
348-
set_relation(name, value.substitute(object.substitutable))
344+
if !value.respond_to?(:substitute)
345+
value = __build__(name, value, association)
349346
end
347+
348+
set_relation(name, value.substitute(object.substitutable))
350349
else
351350
__build__(name, object.substitutable, association)
352351
end

0 commit comments

Comments
 (0)