ransack
ransack copied to clipboard
Search on two associations where the second one is part of the default scope generates invalid SQL
See the minitest to demonstrate the problem: https://gist.github.com/nagyt234/b4a9bb210f7cf83262ab The generated SQL contains
AND "documents_revisions"."code" = 'BBB'
instead of
AND "documents"."code" = 'BBB'
The problem appears only if the default scope on model Revision applied and the first condition refer to an other association. Note, that this error cames up on Rails 4.1.2 (used in my project), on the newest Rails 4.2 and on Rails 5 beta either.
Issue reproduced. I messed around with it and added another test for fun here: https://gist.github.com/jonatack/1b64c924a81283e3ec83