jackc / jackc/edge

.find_forest broken in 0.5.0

Open
#19 1 comment 0 reactions 0 assignees View on GitHub
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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.