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

Reload through_record that has been destroyed in create_through_record #27838

Merged
merged 1 commit into from Jan 31, 2017

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Jan 29, 2017

This is an alternative of #27714.

If has_one :through association has set nil, through_record is
destroyed but still remain loaded target in through_proxy until
reload or reset explicitly.

If through_proxy is not reset (remain destroyed (frozen) target),
setting new record causes RuntimeError: Can't modify frozen hash.

To prevent RuntimeError, should reload through_record that has been
destroyed in create_through_record.

…cord`

This is an alternative of rails#27714.

If `has_one :through` association has set `nil`, `through_record` is
destroyed but still remain loaded target in `through_proxy` until
`reload` or `reset` explicitly.

If `through_proxy` is not reset (remain destroyed (frozen) target),
setting new record causes `RuntimeError: Can't modify frozen hash`.

To prevent `RuntimeError`, should reload `through_record` that has been
destroyed in `create_through_record`.
@rafaelfranca
Copy link
Member

Why this alternative is better than reseting the proxy?

@kamipo
Copy link
Member Author

kamipo commented Jan 31, 2017

I tried to fix stale_state? to regard as destroyed target is staled.
But some tests expects destroyed target is not staled (doesn't expect reload or reset destroyed target immediately).

assert @pirate.ship.destroyed?

This means that the reloading first is a breaking change. So I changed to reloading on demand.

@rafaelfranca rafaelfranca merged commit 505463c into rails:master Jan 31, 2017
@rafaelfranca
Copy link
Member

Makes sense. Thansk

@kamipo kamipo deleted the reload_destroyed_through_record branch January 31, 2017 06:33
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

3 participants