ClosureTree / closure_tree

Easily and efficiently make your ActiveRecord models support hierarchies
https://closuretree.github.io/closure_tree/
MIT License
1.84k stars 240 forks source link

Cannot preload self_and_descendants #70

Open tulak opened 11 years ago

tulak commented 11 years ago

When trying to load hash_tree as much effectively as can I came into an issue. In model I have set order option act_as_tree order: 'name' And then when trying to call Right.includes(:self_and_descendants) mysql throws error:

Unknown column 'name' in 'order clause

That's because ActiveRecord are trying to preload rIght_hierarchies without joining the model (Right) table.

I triet to dig into the code and find the bug. But only found that in closure_tree/model.rb there is _ct.has_many_with_order_option when defining has_many association on model.

Couldn't find out the way how to implement it to work with preloading and also preserve ordering feature on preloaded models. Any ideas ?

viktorchukhantsev commented 6 years ago

+1