Skip to content
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

Refs #28025 nullify *_type column on polymorphic associations on :nu… #28078

Merged
merged 3 commits into from Jan 15, 2019

Conversation

laertispappas
Copy link
Contributor

@laertispappas laertispappas commented Feb 20, 2017

Nullify polymorphic *_type column on dependent: :nullify strategy.

Summary

This PR addresses the issue described in #28025. On dependent: :nullify strategy only the foreign key of the relation is nullified. However on polymorphic associations the *_type column is not nullified leaving the record with a NULL *_id but the *_type column is present.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@haines
Copy link

haines commented Jul 7, 2017

Nice! I think this needs to be extended to handle to polymorphic has_one relationships as well.

Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant in Rails 6 (205aa14). I agree with @haines, behaviour should be consistent with has_one if its going to be changed. I think all you need to do is add record[reflection.type] = nil if reflection.type to

and add another test.

@laertispappas laertispappas force-pushed the lp/nullify_polymorphic_type branch 4 times, most recently from da151d8 to 4940d90 Compare September 30, 2018 15:25
@laertispappas
Copy link
Contributor Author

@gmcgibbon @haines thanks for the feedback. I made some changes can you have a look?

Copy link

@haines haines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding it to the has_one, this looks good to me!

Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Please squash your commits and add a changelog entry in activerecord/CHANGELOG to make this mergeable.

@laertispappas
Copy link
Contributor Author

@gmcgibbon thank you for the feedback. Squashed and updated CHANGELOG / docs.

Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, two more things and then it should be good to go!

activerecord/CHANGELOG.md Show resolved Hide resolved
guides/source/association_basics.md Outdated Show resolved Hide resolved
@laertispappas
Copy link
Contributor Author

@gmcgibbon Updated. Thanks.

Copy link
Member

@eileencodes eileencodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Sorry for the delay @laertispappas - can you fix the conflicts and I can merge once that's done.

activerecord/lib/active_record/associations.rb Outdated Show resolved Hide resolved
@laertispappas
Copy link
Contributor Author

@eileencodes @kamipo thanks for the feedback. I've made some changes.

activerecord/CHANGELOG.md Outdated Show resolved Hide resolved
@kamipo kamipo merged commit 41ffddb into rails:master Jan 15, 2019
@kamipo
Copy link
Member

kamipo commented Jan 15, 2019

Thanks!

@laertispappas
Copy link
Contributor Author

Pleasure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants