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
This is probably more of a question than a definite issue, but it seems to me that the self_and_descendants association on a node is a bit misleading, in that whenever self is a childless node it seems to return an empty collection instead of a length-of-one collection containing only self.
I'm not sure if I'm missing something, but it seems to me that the INNER JOIN that's getting called as a result of that relation is actually trying to inner join the *_hierarchies table with an additional condition that the *_hierarchies.ancestor_id = $1, but since the node in question doesn't have any children, its ID (the $1 in the query) hasn't ever been added to the *_hierarchies table's ancestor_id column (though it is in the descendant_id column, obviously). This results in an empty table being returned, and thus an empty ActiveRecord::Assocations::CollectionProxy object.
Here's an example of the query that's invoked in my app when I call self_and_descendants on an AdministratorGroup object:
And here's a screenshot of my administrator_group_hierarchies table. As you can see, because the AdministratorGroup in question (which does exist in my administrator_groups table) is a bottom-level node, its ID (18) hasn't been added to the ancestor_id column in the administrator_group_hierarchies join table, and thus results in an empty inner join:
Given the above, am I off base with this interpretation? Is this the intended functionality? I'll be honest, I struggled a bit to find exactly where in your codebase the above SQL is being generated, though I'm happy to pursue opening a PR to address it if you do in fact believe it to be a bug. I would just need a little more context for how that query is being created before I do.
Thanks!
The text was updated successfully, but these errors were encountered:
Hey Team,
This is probably more of a question than a definite issue, but it seems to me that the
self_and_descendants
association on a node is a bit misleading, in that wheneverself
is a childless node it seems to return an empty collection instead of a length-of-one collection containing onlyself
.I'm not sure if I'm missing something, but it seems to me that the INNER JOIN that's getting called as a result of that relation is actually trying to inner join the
*_hierarchies
table with an additional condition that the*_hierarchies.ancestor_id = $1
, but since the node in question doesn't have any children, its ID (the$1
in the query) hasn't ever been added to the*_hierarchies
table'sancestor_id
column (though it is in thedescendant_id
column, obviously). This results in an empty table being returned, and thus an emptyActiveRecord::Assocations::CollectionProxy
object.Here's an example of the query that's invoked in my app when I call
self_and_descendants
on anAdministratorGroup
object:And here's a screenshot of my
administrator_group_hierarchies
table. As you can see, because theAdministratorGroup
in question (which does exist in myadministrator_groups
table) is a bottom-level node, its ID (18) hasn't been added to theancestor_id
column in theadministrator_group_hierarchies
join table, and thus results in an empty inner join:Given the above, am I off base with this interpretation? Is this the intended functionality? I'll be honest, I struggled a bit to find exactly where in your codebase the above SQL is being generated, though I'm happy to pursue opening a PR to address it if you do in fact believe it to be a bug. I would just need a little more context for how that query is being created before I do.
Thanks!
The text was updated successfully, but these errors were encountered: