Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash_tree not using STI scope on Rails 5 #220

Closed
aaronrussell opened this issue Jun 17, 2016 · 6 comments
Closed

hash_tree not using STI scope on Rails 5 #220

aaronrussell opened this issue Jun 17, 2016 · 6 comments

Comments

@aaronrussell
Copy link
Contributor

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.

@aaronrussell
Copy link
Contributor Author

I can add a bit more info to this. It is not just the STI scope that is affected - it is any scope.
eg:

Page.where(status: 'published').hash_tree

Generates the same query above, ignoring the where condition.

@mceachen
Copy link
Collaborator

mceachen commented Jun 17, 2016 via email

@aaronrussell
Copy link
Contributor Author

aaronrussell commented Jun 17, 2016

closure_tree is a core part of my project - https://github.com/pushtype/push_type - and I'm kind of optimistic not too much is broken in rails 5 (i may regret saying that :))

The only closure_tree related issues I've found is this one, and the issue fixed in #209.

If you like I can try and help you with your first step (create a fork with a rails5 gemfile), so I can let you know the lay of the land. I'm not sure I'll be able to help too much with 2 & 3, but can definitely help you with 4!

@mceachen
Copy link
Collaborator

mceachen commented Jun 17, 2016 via email

@aaronrussell
Copy link
Contributor Author

I've created a rails-5 fork with new gemset: https://github.com/aaronrussell/closure_tree/tree/rails-5

All of your tests pass with activerecord 5. I'm not sure if that's good thing or a worrying thing 😟 . Next week I'll try and add a failing test for this specific issue. Hopefully though, this upgrade won't cause too many nightmares.

@mceachen
Copy link
Collaborator

mceachen commented Jun 17, 2016 via email

@seuros seuros closed this as completed in 18a9bc8 Jun 20, 2016
seuros added a commit that referenced this issue Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants