-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix mongoize update all array operators master #5823
Fix mongoize update all array operators master #5823
Conversation
…ge $in and $nin when provided as a symbol as well as a string
…$pop in special handling conditions for Mongoize
depeche_mode.update_attribute(:genres, ["pop", "electronic", "dance" ]) | ||
new_order.update_attribute(:genres, ["electronic", "pop", "dance"]) | ||
context.update_all("$pullAll" => { genres: ["pop", "electronic"] }) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JohnMaguir for $pullAll it is better to prepare multiple entries in the data to be pulled from the array, just to cover it fully:
depeche_mode.update_attribute(:genres, ["pop", "electronic", "dance", "pop" ])
new_order.update_attribute(:genres, ["electronic", "pop", "electronic", "dance"])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @dem updated now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Thank you 🙇
Issue when using
$pull
or$pop
withupdate_all
Atomic operators that deal with arrays or sets:
$addToSet
,$push
,$pull
,$pop
,$pullAll
Only
$addToSet
and$push
are covered by current tests and$pull
,$pop
functionality is broken asMongoid::AtomicUpdatePreparer.mongoize_for
returnsnil
for query such asupdate_all("$pull" => { genres: "electronic" })
This became an issue after fixes from #5814 as correct
key
is now being passed toMongoid::AtomicUpdatePreparer.mongoize_for
Fix is to
mongoize
value the same way it is for$addToSet
or$push
.Also added tests for
$pullAll
even though it is currently working but good to have all operators covered.Corresponding fix for 8.1 branch - #5824