.find_forest broken in 0.5.0
- Dominant language
- Ruby
- Stars
- 90
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
In 0.4.4:
``` ruby
Group.where(name: "Universal Questions").find_forest
```
will generate the following SQL:
``` sql
WITH RECURSIVE "all_nodes" AS ( SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" WHERE "prompts"."type" IN ('Group') AND "prompts"."name" = $1 UNION SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" INNER JOIN "all_nodes" ON "prompts"."parent_id" = "all_nodes"."id" ) SELECT * FROM "all_nodes" INNER JOIN "prompts" ON "all_nodes"."id" = "prompts"."id" ORDER BY position
```
``` ruby
Group.where(name: "Universal Questions").find_forest.first.children.count #70
```
In 0.5.0:
The same ruby statement generates the following query:
``` sql
WITH RECURSIVE all_nodes AS (
SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" WHERE "prompts"."type" IN ('Group') AND "prompts"."name" = 'Universal Questions'
UNION
SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" INNER JOIN all_nodes ON "prompts"."parent_id"=all_nodes."id" WHERE "prompts"."type" IN ('Group')
)
SELECT "prompts".* FROM "prompts" INNER JOIN all_nodes USING("id") WHERE "prompts"."type" IN ('Group') ORDER BY position
```
``` ruby
Group.where(name: "Universal Questions").find_forest.first.children.count #0
```
Returning only a single record with the `descendants` & `children` properties being empty arrays.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the find_forest entry point and run the reproduction query from the issue against version 0.5.0, then compare its recursive SQL with the 0.4.4 output. Done means the generated query includes the expected descendants and Group.where(name: "Universal Questions").find_forest.first.children.count returns 70 instead of 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100