Skip to content

hash_tree not using STI scope on Rails 5 #220

Closed
@aaronrussell

Description

@aaronrussell

Testing one of my apps for Rails 5, and have noticed hash_tree doesn't use the STI scope of the calling class. I can't pinpoint exactly where the issue is in the code, but can confirm the following SQL statements.

When calling Page.hash_tree

Rails 4.2

SELECT "nodes".* FROM "nodes" INNER JOIN (
  SELECT descendant_id, MAX(generations) as depth
  FROM "node_hierarchies"
  GROUP BY descendant_id

) AS generation_depth
  ON "noes".id = generation_depth.descendant_id
  WHERE "nodes"."type" IN ('Page')
  ORDER BY generation_depth.depth, sort_order

Rails 5

SELECT "nodes".* FROM "nodes" INNER JOIN (
  SELECT descendant_id, MAX(generations) as depth
  FROM "node_hierarchies"
  GROUP BY descendant_id

) AS generation_depth
  ON "nodes".id = generation_depth.descendant_id
  ORDER BY generation_depth.depth, sort_order

Notice that rails 5 does't include the WHERE "nodes"."type" IN ('Page') condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions