-
Notifications
You must be signed in to change notification settings - Fork 212
Squeel breaks the use of subqueries with associations #272
Comments
Confirmed. I have a failing test case written and working on getting binds passed through when subquerying against an association proxy. |
@dnagir Could you give master a shot, and let me know if this resolves your issue? |
@ernie unfortunately I had to remove squeel from the project due to this issue (and in anticipation of others upgrading to Rails 4). But if my repro above works then pretty sure you fixed it. |
The master branch fixes the issue, please release a new version. |
Actually, it appears to cause a different issue. It appears that when one parameter The bad query: SELECT "test_cases".* FROM "test_cases" WHERE "test_cases"."problem_id" = $1 AND "test_cases"."id" IN (SELECT "test_case_relations"."test_case_id" FROM "test_sets" INNER JOIN "test_case_relations" ON "test_case_relations"."test_set_id" = "test_sets"."id" WHERE "test_sets"."problem_id" = $1 AND "test_sets"."prerequisite" = 't' ORDER BY "test_sets".problem_order ASC) ORDER BY "test_cases".problem_order ASC is built using: class Problem < ActiveRecord::Base
has_many :prerequisite_sets, -> { where(:prerequisite => true).rank(:problem_order) }, :class_name => TestSet
end
class TestSet < ActiveRecord::Base
belongs_to :problem
has_many :test_case_relations, :dependent => :destroy
end
problem.test_cases.where(:id => problem.prerequisite_sets.joins(:test_case_relations).select(:test_case_relations => :test_case_id)) Stacktrace of original error:
|
Had a similar problem, had to workaround by converting relation to a string:
|
Any updates on this? |
@cameron-martin If there were updates for this you can be assured that they would be posted here. |
It only happens on Postgresql, because it's using a different binding way to sqlite & mysql. I'm digging it, would response later. |
@ronalchn @cameron-martin Please try master branch. It should be fixed now 😄 Thank you very much. |
@bigxiang same issue on master branch |
hi @kaleemullah ,would you please give me a gist to represent the error ? It should be very helpful for me. |
It looks like rails/rails#16238 |
The issue has originally been open in the Rails repo here rails/rails#12409
But it is definitely a squeel issue because it works as expected without it.
The minute we introduce squeel into the example - it fails.
Full repro:
When executed produces following output:
When we uncomment
require 'squeel'
, the output is correct and there are no errors:The text was updated successfully, but these errors were encountered: