Skip to content

ActiveRecord::Dirty methods do not use nilify_blanks logic #23

@chrisdpeters

Description

@chrisdpeters

Not sure if this is pushing too far, but I get incorrect behavior when trying to use methods like changed? and changes when nilify_blanks is applied to a model.

For example:

--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
email:
- 
- ''
notes:
- 
- ''

I had to configure nilify_blanks like this:

nilify_blanks before: :validation

And then do this clunky logic to work around this problem:

# Save referral. We want to track if anything changed to decide how to treat any comments below.
referral.attributes = referral_attributes
# Force nilify_blanks to do its thing before validation so we can check for the true changes.
referral.valid?
# See if there were changes before updating the referral record. (This will always be `false` after we run
# `update`.)
referral_changed = referral.changed?
referral.save

Not sure how involved it would be to fix this or if it would be appropriate to do so. Or is there a better way to do what I'm trying to accomplish?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions