ransack
ransack copied to clipboard
Double self join generates incorrect sql
I have the following structure:
Item -> ItemInfo
| ^
\/
I'd like to search for item_infos which has parent with something in their item_infos.
ItemInfo.ransack({ items_parent_item_info_name_cont: "Foo" })
This returns almost the good query, it the self join on parent_item is handled fine, but the last item_info is joined on item and not on parent_item
SELECT "item_infos".* FROM "item_infos" LEFT OUTER JOIN "items" ON "items"."item_info_id" = "item_infos"."id" LEFT OUTER JOIN "items" "parents_items" ON "parents_items"."id" = "items"."parent_item_id" LEFT OUTER JOIN "item_infos" "item_infos_items" ON "item_infos_items"."id" = "items"."item_info_id" WHERE ("item_infos_items"."name" LIKE '%Foo%')
That is
... ON "item_infos_items"."id" = "items"."item_info_id"
should be
... ON "item_infos_items"."id" = "parent_items"."item_info_id"
Testcase: https://gist.github.com/mfazekas/0e012b4dfc387afd704b517f98201366
+1
Hi @mfazekas, thanks for the bug report. Any chance of writing a failing test? It will help the issue get resolved faster.
Cheers
@seanfcarroll you saw the gist at the end of the report that should be a failing test. I assume you'd like me add that test to your testsuite, right?
@mfazekas that would be awesome
+1