ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Double self join generates incorrect sql

Open mfazekas opened this issue 8 years ago • 5 comments

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

mfazekas avatar Feb 17 '17 09:02 mfazekas

+1

swordray avatar Dec 08 '17 08:12 swordray

Hi @mfazekas, thanks for the bug report. Any chance of writing a failing test? It will help the issue get resolved faster.

Cheers

scarroll32 avatar Feb 07 '18 15:02 scarroll32

@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 avatar Feb 07 '18 16:02 mfazekas

@mfazekas that would be awesome

scarroll32 avatar Feb 18 '18 13:02 scarroll32

+1

tommasodri avatar Feb 27 '19 10:02 tommasodri