Hello!


I think, there is bug (imperfection) of `eager_graph` for models with 
`rcte_tree` plugin:



> Item.eager(:ancestors).all.first

# I, [2019-05-17T17:31:24.789997 #10275] INFO -- : (0.000501s) SELECT * 
FROM "items" ORDER BY "parent_id", "position"

# I, [2019-05-17T17:31:24.791887 #10275] INFO -- : (0.000762s) WITH 
RECURSIVE "t" AS (SELECT * FROM (SELECT "id" AS "x_root_x", "items".* FROM 
"items" WHERE ("id" IN (1)) ORDER BY "parent_id", "position") AS "t1" UNION 
ALL (SELECT * FROM (SELECT "t"."x_root_x", "items".* FROM "items" INNER 
JOIN "t" ON ("t"."parent_id" = "items"."id") ORDER BY "parent_id", 
"position") AS "t1")) SELECT * FROM "t" AS "items" ORDER BY "parent_id", 
"position"

# => #<Item @values={:id=>3, :name=>"Child", :position=>1, :parent_id=>1}>

> Item.eager(:ancestors).all.first.root

# I, [2019-05-17T17:29:07.216099 #10275] INFO -- : (0.000482s) SELECT * 
FROM "items" ORDER BY "parent_id", "position"

# I, [2019-05-17T17:29:07.217917 #10275] INFO -- : (0.000741s) WITH 
RECURSIVE "t" AS (SELECT * FROM (SELECT "id" AS "x_root_x", "items".* FROM 
"items" WHERE ("id" IN (3)) ORDER BY "parent_id", "position") AS "t1" UNION 
ALL (SELECT * FROM (SELECT "t"."x_root_x", "items".* FROM "items" INNER 
JOIN "t" ON ("t"."parent_id" = "items"."id") ORDER BY "parent_id", 
"position") AS "t1")) SELECT * FROM "t" AS "items" ORDER BY "parent_id", 
"position"

# => #<Item @values={:id=>1, :name=>"Root", :position=>1, :parent_id=>nil}>

> Item.eager_graph(:ancestors).all.first.root

# I, [2019-05-17T17:29:17.217909 #10275] INFO -- : (0.000734s) SELECT 
"items"."id", "items"."name", "items"."position", "items"."parent_id", 
"ancestors"."id" AS "ancestors_id", "ancestors"."name" AS "ancestors_name", 
"ancestors"."position" AS "ancestors_position", "ancestors"."parent_id" AS 
"ancestors_parent_id" FROM "items" LEFT OUTER JOIN (SELECT * FROM "items" 
ORDER BY "parent_id", "position") AS "ancestors" ON 
("ancestors"."parent_id" = "items"."id") ORDER BY "parent_id", "position"

# => #<Item @values={:id=>3, :name=>"Child", :position=>1, :parent_id=>1}>



Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/8fa17324-4f22-49c9-934a-d739dda13e95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to