close
Skip to content

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

Merged
kamipo merged 3 commits into
rails:masterfrom
laertispappas:lp/nullify_polymorphic_type
Jan 15, 2019
Merged

kamipo merged 3 commits into
rails:masterfrom
laertispappas:lp/nullify_polymorphic_type

Conversation

@laertispappas

@laertispappas laertispappas commented Feb 20, 2017 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

haines commented Jul 7, 2017 •

Copy link
Copy Markdown
Contributor

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

@gmcgibbon gmcgibbon left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

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

@haines haines left a comment

Copy link
Copy Markdown
Contributor

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!

@gmcgibbon gmcgibbon left a comment

Copy link
Copy Markdown
Member

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
laertispappas force-pushed the lp/nullify_polymorphic_type branch from 4940d90 to df85d55 Compare October 3, 2018 21:36
@rails-bot rails-bot Bot added the docs label Oct 3, 2018
@laertispappas

Copy link
Copy Markdown
Contributor Author

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

@gmcgibbon gmcgibbon left a comment

Copy link
Copy Markdown
Member

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!

Comment thread activerecord/CHANGELOG.md Resolved
Comment thread guides/source/association_basics.md Resolved
@laertispappas
laertispappas force-pushed the lp/nullify_polymorphic_type branch from df85d55 to 17d2993 Compare October 4, 2018 19:13
@laertispappas

Copy link
Copy Markdown
Contributor Author

@gmcgibbon Updated. Thanks.

@eileencodes eileencodes left a comment

Copy link
Copy Markdown
Member

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.

Comment thread guides/source/association_basics.md Resolved
@laertispappas
laertispappas force-pushed the lp/nullify_polymorphic_type branch from 17d2993 to e5a9774 Compare January 3, 2019 13:09
@laertispappas

Copy link
Copy Markdown
Contributor Author

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

@laertispappas
laertispappas force-pushed the lp/nullify_polymorphic_type branch from acf4f37 to f2c7614 Compare January 3, 2019 15:18
Comment thread activerecord/CHANGELOG.md Resolved
Comment thread guides/source/association_basics.md Resolved
Comment thread guides/source/association_basics.md Resolved
@laertispappas
laertispappas force-pushed the lp/nullify_polymorphic_type branch from 49b180a to bdf59e5 Compare January 7, 2019 20:16
Comment thread guides/source/association_basics.md Resolved
@laertispappas
laertispappas force-pushed the lp/nullify_polymorphic_type branch from bdf59e5 to 105f6f6 Compare January 8, 2019 20:03
@laertispappas
laertispappas force-pushed the lp/nullify_polymorphic_type branch from 105f6f6 to 78bb689 Compare January 8, 2019 22:18
@kamipo
kamipo merged commit 41ffddb into rails:master Jan 15, 2019
@kamipo

kamipo commented Jan 15, 2019

Copy link
Copy Markdown
Member

Thanks!

@laertispappas

Copy link
Copy Markdown
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.

7 participants