You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! This gem looks super interesting but I've got quite a weird use case and I was wondering if there is a way to achieve this with Ancestry.
Imagine two classes, Node and Category:
Node has belongs_to: :parent, class_name: 'Node' and belongs_to: :category
Category has belongs_to: :parent, class_name: 'Category'
So we can build hierarchies like:
A: node112 -> .parent == node11 -> .parent == node1 (which would be ancestry on the parent_id attribute)
B: but also node112 -> .category == category12 -> .parent == category1 (where we first go over the the category_id and then parent_id)
Ancestry paths would look something like:
A: node1/node11/node112
B: category1/category12/node112
So the classes would contain something like:
classNodehas_ancestryancestry_column: :parent_id,class: Node# option :class is a fantasy construct herehas_ancestryancestry_column: :category_id,class: CategoryendclassCategoryhas_ancestryancestry_column: :parent_id,class: Categoryend
However for Node this would likely be a problem since ancestry (if I anderstand correctly) would not know that node.parent should go on the parent_id ancestry while node.category would take once the category_id and then the parent_id.
Do I understand correctly that such a structure is currently not possible with ancestry?
Cheers!
Kalsan
The text was updated successfully, but these errors were encountered:
closure trees work much better for going across class boundaries.
If you want to use ancestry, STI has worked for many people.
In my main code base, we have created a level of indirection to bridge that gap, but that causes all sorts of nuances that severely impact performance. So I'm in the process of removing those where possible.
Related, or possibly unrelated: people have wanted to have multiple trees per node, but this into in the short term cards.
Hi! This gem looks super interesting but I've got quite a weird use case and I was wondering if there is a way to achieve this with Ancestry.
Imagine two classes,
Node
andCategory
:Node
hasbelongs_to: :parent, class_name: 'Node'
andbelongs_to: :category
Category
hasbelongs_to: :parent, class_name: 'Category'
So we can build hierarchies like:
node112
->.parent == node11
->.parent == node1
(which would beancestry
on theparent_id
attribute)node112
->.category == category12
->.parent == category1
(where we first go over the thecategory_id
and thenparent_id
)Ancestry paths would look something like:
node1/node11/node112
category1/category12/node112
So the classes would contain something like:
However for Node this would likely be a problem since ancestry (if I anderstand correctly) would not know that
node.parent
should go on theparent_id
ancestry whilenode.category
would take once thecategory_id
and then theparent_id
.Do I understand correctly that such a structure is currently not possible with ancestry?
Cheers!
Kalsan
The text was updated successfully, but these errors were encountered: