Skip to content

Strange Ruby behavior in Mongoid 8.0 that doesn't happen in Mongoid 7.5 #5902

Closed Answered by jamis
rsosag asked this question in Q&A
Discussion options

You must be logged in to vote

Hello,

I'm sorry this one was so mysterious! It's a consequence of #5787, which fixed a significant performance issue with validations on associations.

So, you're right, that the issue has to do with attr_accessor. Validations are now only run on associated records if the records have changed. Because setting a value via attr_accessor does not mark the record as changed (that only happens when persistable fields are modified), the validation (and before_validation) callbacks aren't being invoked. To work around this, would it be feasible for you to do something like:

class BusinessSettings
  include Mongoid::Document

  def role_or_custom_role_id=(value)
    # move the logic from `set_rol…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rsosag
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants