stefankroes / ancestry

Organise ActiveRecord model into a tree structure
MIT License
3.72k stars 458 forks source link

Root node has no siblings. #627

Closed kbrock closed 1 year ago

kbrock commented 1 year ago

This is a breaking change.

Each tree is a unique tree, so the root node of a tree has no siblings.

Fixes #590

kbrock commented 1 year ago

@kshnurov do you feel that a root node should have all other root nodes as siblings?

Would you prefer that this was behind a feature switch? Seems to me that the current behavior is a bug.

kshnurov commented 1 year ago

@kshnurov do you feel that a root node should have all other root nodes as siblings?

Yes, it should, I might want to get other root nodes without having to do where(ancestry: self.class.root_ancestry), where root_ancestry is an internal gem method not even described in README.

590 can just do root? ? nil : siblings without having all users of this gem to rewrite their code because of the breaking change no one really asked for.

kbrock commented 1 year ago

To find roots you just use Model.roots. No internal methods required.

Looks like closure_trees has root.siblings point to all roots as well. I will tell #590 how to solve his problem.

closing