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

recursive has_many queries #40

Open
smenor opened this issue Mar 31, 2023 · 0 comments
Open

recursive has_many queries #40

smenor opened this issue Mar 31, 2023 · 0 comments

Comments

@smenor
Copy link

smenor commented Mar 31, 2023

We have a hierarchical tree of X which this works well for but each leaf on that tree has_many Y relations and we need a way to recursively select all of the Y from all descendants of a particular instance x of X

So / in pseudocode

class X < ActiveRecord
  belongs_to :parent, class_name: "X", optional: true, touch: true
  has_many :children, inverse_of: :parent, class_name: "X", foreign_key: :parent

  has_many :y
end

class Y < ActiveRecord
  belongs_to :x
end

Then we would want

x = X.all.sample

ys = x.all_child_ys # this is all elements of Y which are in z.ys for all z which are of type X and children of x

Is there a way to do this now or some ( reasonable ) way to add it as a new feature ?

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

1 participant