I’m pretty sure I’m doing something wrong, but I’m not sure *what* I’m
doing wrong with a particular many_to_many setup. I have made a minimal
reproduction in a gist, but it’s still fairly complex. I have tried to make
sure that there are enough comments in-line.

https://gist.github.com/8e424c08ae88a96692b13fee03f5b613

In short, I have Category <=> Product through CategoryProduct.
CategoryProduct is almost a pure join table, but also has an attribute,
sort_order. When I select products through a particular category, I want
the products ordered by (categories_products.sort_order,
products.sort_order). This works.

Category is also a tree structure using the rcte_tree plug-in, and I want
to be able to answer 'what are the products associated with category X and
its descendants'? This is something I am trying to do with the
`descended_from_category` dataset method on Product.

The final twist to what I’m seeing is that I am using the
dataset_associations plug-in (I’m using many more than this, but this is
the one that seems to be breaking things most).

So I’m left with a few questions:

1. Is this a bug?

2. Even if this is a bug, is there a better way to do what I’m trying to do?

3. Having to do
category.this.select(:category_id).union(category.descendants_dataset.select(:category_id)
feels clunky compared to Closure Tree for Rails, which has a
self_and_descendants method. It might be doing the same thing internally
(haven’t looked); is this a worthwhile feature request/PR that I can make?

-a
-- 
Austin Ziegler • [email protected][email protected]
http://www.halostatue.ca/http://twitter.com/halostatue

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to