Skip to content

Add support for multiple trees in the query builder #4979

Description

@grantfitzsimmons

Component of #4833

From @realVinayak:

regarding query builder backend, this can be very simply (and naively) accomplished by passing the object type and getting the appropriate treedef here:

treedef = get_treedef(query.collection, table.name)

Figure out why it will "just work". the above assumes that defitems cannot be shared (like same rank ITSELF wouldn't appear in two trees). Like if Kingdom is treedefitemid=1 in one treedef, it is also not treedefitemid=1 in another treedef. basically, how the trees in specify works currently (so no worries I believe)

BUT, I think that'll be inefficient. You can make it considerably more efficient (think why the above isn't) very simply, by including the objecttype equality to the join criterion (well, technically just the first node, but you get the point)
(

query = query.outerjoin(ancestor, ancestors[-1].ParentID == getattr(ancestor, ancestor._id))
)

^ofc that's for querying a specific tree. querying all trees at once is simpler (but I guess you can't say (any tree) -> species), like you could have (Fossil) -> species)

theoretically, doing something like (any tree) -> species is also straightforward (will think about perf impact). you could have an OR condition here (look up all treedefitemids which have species, put them in the OR below

treedefitem_param = sql.bindparam('tdi_%s' % query.param_count, value=treedef.treedefitems.get(name=tree_rank).id)

Metadata

Metadata

Assignees

Labels

1 - RequestA request made by a member of the community2 - QueriesIssues that are related to the query builder or queries in general2 - TreesIssues that are related to the tree system and related functionalities.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions