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

Restoring has_one with recursive: true leads to ActiveRecord::StatementInvalid #171

Closed
wants to merge 2 commits into from

Conversation

srecnig
Copy link
Contributor

@srecnig srecnig commented Oct 6, 2014

i'm using paranoia with rails 4.1.5 and postgres. when trying to restore a record with a has_one association, activerecord will build an invalid query, e.g.

SELECT  "authors".* FROM "authors"  WHERE ("authors"."deleted_at" IS NOT NULL) AND (user_id)  ORDER BY "authors"."id" ASC LIMIT 1

as far as i understand it, the reason seems to be that the where call in restore_associated_records is not given a hash, but rather a string and the id. activerecord interprets this as raw sql and therefore creates the invalid AND(user_id).

changing this to a hash fixes the problem in my app and does not raise any new errors with the test suite. btw, i can reproduce the error only in my app, and not with the test suite that ships with paranoia, i think it's because sqlite does not have a problem with such a query?

@jhawthorn
Copy link
Collaborator

@srecnig Is it possible to add a failing test case? Otherwise this looks good.

@srecnig
Copy link
Contributor Author

srecnig commented Nov 27, 2014

@jhawthorn done.

@jhawthorn
Copy link
Collaborator

Thanks! Excellent test. Makes it clear that this was broken on all databases.

This has been merged as ec04c68. I plan to release a gem including this fix the next day or two.

Might consider setting up travisci to test against all 3 common databases.

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.

None yet

2 participants