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

@rails-bot rails-bot commented Feb 20, 2017

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.

@laertispappas laertispappas force-pushed the lp/nullify_polymorphic_type branch from c7b881d to 12b81b8 Feb 20, 2017
@haines
Copy link

@haines 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

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 Sep 30, 2018
@laertispappas
Copy link
Contributor Author

@laertispappas laertispappas commented Oct 1, 2018

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

haines
haines approved these changes Oct 1, 2018
Copy link

@haines haines left a comment

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

Copy link
Member

@gmcgibbon gmcgibbon left a comment

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 Oct 3, 2018
@rails-bot rails-bot added the docs label Oct 3, 2018
@laertispappas
Copy link
Contributor Author

@laertispappas laertispappas commented Oct 3, 2018

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

Copy link
Member

@gmcgibbon gmcgibbon left a comment

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 laertispappas force-pushed the lp/nullify_polymorphic_type branch from df85d55 to 17d2993 Oct 4, 2018
@laertispappas
Copy link
Contributor Author

@laertispappas laertispappas commented Oct 5, 2018

@gmcgibbon Updated. Thanks.

Copy link
Member

@eileencodes eileencodes left a comment

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
guides/source/association_basics.md Outdated Show resolved Hide resolved
@laertispappas laertispappas force-pushed the lp/nullify_polymorphic_type branch from 17d2993 to e5a9774 Jan 3, 2019
@laertispappas
Copy link
Contributor Author

@laertispappas laertispappas commented Jan 3, 2019

@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 Jan 3, 2019
activerecord/CHANGELOG.md Outdated Show resolved Hide resolved
guides/source/association_basics.md Outdated Show resolved Hide resolved
guides/source/association_basics.md Outdated Show resolved Hide resolved
@laertispappas laertispappas force-pushed the lp/nullify_polymorphic_type branch from 49b180a to bdf59e5 Jan 7, 2019
guides/source/association_basics.md Outdated Show resolved Hide resolved
@laertispappas laertispappas force-pushed the lp/nullify_polymorphic_type branch from bdf59e5 to 105f6f6 Jan 8, 2019
@laertispappas laertispappas force-pushed the lp/nullify_polymorphic_type branch from 105f6f6 to 78bb689 Jan 8, 2019
@kamipo kamipo merged commit 41ffddb into rails:master Jan 15, 2019
0 of 2 checks passed
@kamipo
Copy link
Member

@kamipo kamipo commented Jan 15, 2019

Thanks!

@laertispappas
Copy link
Contributor Author

@laertispappas laertispappas commented Jan 16, 2019

Pleasure

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

Successfully merging this pull request may close these issues.

None yet

7 participants