Handle assignments in an ActiveModel::Dirty-friendly way #2658
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proposal for solving ActiveModel::Dirty related issues.
Previously saving an attachment takes following process:
#{column}_will_change!
After this PR, it will be like:
#{column}_will_change!
)The reason for introducing the idea of temporary identifier is that there are the cases we can't determine the identifier on the attachment assignment - an identifier is made from the filename, but filename can be overridden to reference another attribute in the model and in this case we can't determine the final filename until the record is saved (i.e. that column can be assigned after the attachment assignment).
Doing this allows us to reflect
#changes
correctly, resulting in fixing #2404. Also not needing to call#{column}_will_change!
fixes #2409 and #2468, as empty changes will no longer be picked up.Any feedback would be appreciated, thanks.