Skip to content

Fixes an exception when a has_one association is recursively restored.#118

Closed
stupergenius wants to merge 1 commit into
rubysherpas:rails4from
stupergenius:rails4
Closed

Fixes an exception when a has_one association is recursively restored.#118
stupergenius wants to merge 1 commit into
rubysherpas:rails4from
stupergenius:rails4

Conversation

@stupergenius
Copy link
Copy Markdown

The original implementation would raise a method_missing exception when a has_one association was recursively restored. The pull request first checks to see if the association is a collection before looping through the deleted items.

@radar
Copy link
Copy Markdown
Collaborator

radar commented Mar 3, 2014

Hi @stupergenius, could you please write a regression test for this?

@pobocks
Copy link
Copy Markdown
Contributor

pobocks commented Mar 6, 2014

Am I correct in thinking that the case of a nullable single collection should also be handled? i.e., if association_data is nil, currently restore fails.

My additional fix, off the top of my head, probably wrong:

...
association_data = send(association.name)
unless association_data.nil?
  if association_data.paranoid?
    if association.collection?
      association_data.only_deleted.each { |record| record.restore(:recursive => true) }
...

@pobocks
Copy link
Copy Markdown
Contributor

pobocks commented Mar 7, 2014

The nil check seems to fix the remaining issue. I've made a new pull request with the combined fix.

#119

pobocks added a commit to pobocks/paranoia that referenced this pull request Mar 7, 2014
  * Based on partial fix by @stupergenius
  * Handles nil case for hasOne associations
pobocks added a commit to harvard-library/inscriptio that referenced this pull request Mar 7, 2014
radar added a commit that referenced this pull request Mar 11, 2014
Regression tests and full fix for #118
radar pushed a commit that referenced this pull request Mar 11, 2014
  * Based on partial fix by @stupergenius
  * Handles nil case for hasOne associations

Fixes #119
@radar radar closed this Mar 11, 2014
@radar
Copy link
Copy Markdown
Collaborator

radar commented Mar 11, 2014

Fixed by #119.

pobocks added a commit to harvard-library/inscriptio that referenced this pull request Mar 13, 2014
pobocks added a commit to harvard-library/inscriptio that referenced this pull request Apr 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants