You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a caveat about default_scope to the README? #86
I just spent way too long trying to figure out why closure_tree wasn't working for me; it turns out that I had declared
default_scope { order('id asc') }
in my model and it was causing trees to misbehave when they contained children whose IDs where less than that of their parent. Perhaps my blunder can be documented to help others avoid similar headaches.
I've come here from the README. But I don't really get the point: what exactly is the problem? I'm in the process of choosing a gem for creating trees, and I'd like to choose closure_tree, but first I'd like to know what the caveat is with this issue.
Thanks for explaining a bit deeper.
Reacted by Brian Kung, Dan Hetherington and Baptiste Lombard
My experience with default_scope is that there are so many gotchas with
this misfeature that it's generally good advice to avoid it.
The issue with closure_tree is that the quite complicated query generation
in this gem can't incorporate arbitrary SQL from the default scope and
generate valid queries.
I suspect this is the problem I'm having too. I've got a default scope thanks to the paranoia gem, and even though none of the records I'm trying to add to a hierarchy it seems like the whole thing isn't working properly with the scope set 😢
I wonder if this could be made to work by having an option to has_closure_tree that would make it always use #unscoped.
Activity
mceachen commentedon May 12, 2014
Bummer! I'll add a warning to the README.
geordee commentedon Sep 28, 2014
Is it just the "order" in the default_scope? How about if I define a default_scope with a "where"?
jmuheim commentedon Dec 8, 2015
I've come here from the README. But I don't really get the point: what exactly is the problem? I'm in the process of choosing a gem for creating trees, and I'd like to choose closure_tree, but first I'd like to know what the caveat is with this issue.
Thanks for explaining a bit deeper.
mceachen commentedon Dec 8, 2015
kaoru commentedon Nov 26, 2018
I suspect this is the problem I'm having too. I've got a default scope thanks to the paranoia gem, and even though none of the records I'm trying to add to a hierarchy it seems like the whole thing isn't working properly with the scope set 😢
I wonder if this could be made to work by having an option to
has_closure_treethat would make it always use#unscoped.