1and1 / acts_as_recursive_tree

Make use of recursive queries in Rails when using Postgresql or SQLite
MIT License
70 stars 2 forks source link

Feature request: multiple parents #37

Open brandondrew opened 2 weeks ago

brandondrew commented 2 weeks ago

I have a use case (a university web site) where I must model supervisor/employee relationships.

These are essentially parent/child relationships, except that anyone can have an arbitrary number of appointments and therefore an arbitrary number of supervisors (though in practice more than 3 is rare). (Think of a professor whose specialty cuts across the boundaries of linguistics and anthropology, or chemistry and biology, etc. If they are also a department chair, then they likely have 3 appointments, and thus report to 3 different people.)

If acts_as_recursive_tree could support a parent_id which is an array or JSONB column (or perhaps parent_ids for a plurality of IDs) that would be extremely helpful. Thanks!

wollistik commented 2 weeks ago

This sounds very interesting 🤔. I can think of specifying directly an Arel node as parent_id with some additional configuration. But honestly I don't know if I will add this here or rethink the whole gem, since there is now built in support for recursive CTEs in Rails 7.2 (see https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-with_recursive).