5

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.

Will I AM
  • 220
  • 1
  • 9
  • 1
    There are some issues with this gist. I tried to run it, but it failed while creating `students` table, because of default value. I've changed the code to generate uuid in AR callback. After that the code works as expected. Tests are passing and generated sql looks ok. – Michał Młoźniak May 09 '17 at 19:59
  • Can you create a gist and put it here? – Will I AM May 10 '17 at 05:11
  • According to the github issue you already resolved the issue, is that true or is your question here still valid? – Matouš Borák May 11 '17 at 04:57
  • Yes, I will post an answer. Thank you for noticing @BoraMa – Will I AM May 16 '17 at 15:52

1 Answers1

0

I have resolved the issue by monkey patching ActiveRecord AliasTracker.

See my gh issue for the full explanation.

Will I AM
  • 220
  • 1
  • 9