I have a model, Student
, that with a habtm relationship with another model, Group
. The following code:
Student.ransack(groups_id_eq: 22839).result
Produces the following SQL:
SELECT "students".* FROM "students"
LEFT OUTER JOIN "groups_students" ON "groups_students"."student_id" = "students"."id"
LEFT OUTER JOIN "groups" ON "groups"."id" = "groups_students"."group_id"
WHERE "groups"."id" = NULL
Notice that it's converting 22839
into NULL
This was working before upgrading to rails 5.
I have another model, User
, with the same habtm relationship with groups. When I try Student.ransack(groups_id_eq: 22839).result
it works and produces the desired SQL. The difference between two models is that Student
has a uuid id, whereas User
Edit: This does appear to be a bug and I've submitted an issue with a more comprehensive gist.
I have resolved the issue by monkey patching ActiveRecord AliasTracker.
See my gh issue for the full explanation.