Skip to content

Commit e25370e

Browse files
authored
MONGOID-3552 add release note (#5313)
1 parent f669217 commit e25370e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/release-notes/mongoid-8.0.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,42 @@ If you want the functionality of neither document being persisted in Mongoid 7 o
408408
and earlier, the ``validate: true`` option can be set on the association. If
409409
you want the functionality of only the Child being persisted, the ``validate:
410410
false`` option can be set on the association.
411+
412+
413+
Update Local HABTM Association Correctly
414+
----------------------------------------
415+
416+
In Mongoid 8, when pushing persisted elements to a HABTM association, the
417+
association will now update correctly without requiring a reload.
418+
For example:
419+
420+
.. code::
421+
422+
class User
423+
include Mongoid::Document
424+
has_and_belongs_to_many :posts
425+
end
426+
427+
class Post
428+
include Mongoid::Document
429+
has_and_belongs_to_many :users
430+
end
431+
432+
user1 = User.create!
433+
user2 = User.create!
434+
435+
post = user1.posts.create!
436+
437+
p post.users.length
438+
# => 1
439+
440+
post.users << user2
441+
442+
p post.users.length
443+
# => 1 in Mongoid 7, 2 in Mongoid 8
444+
445+
p post.reload.users.length
446+
# => 2
447+
448+
As you can see from this example, after pushing ``user2`` to the users array,
449+
Mongoid 8 correctly updates the number of elements without requiring a reload.

0 commit comments

Comments
 (0)