Closed grantfitzsimmons closed 3 months ago
regarding query builder backend, this can be very simply (and naively) accomplished by passing the object type and getting the appropriate treedef here: https://github.com/specify/specify7/blob/4e5722aabb4ae3e8afd2ee487f4bea68eaff83d1/specifyweb/stored_queries/query_construct.py#L42 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) (https://github.com/specify/specify7/blob/4e5722aabb4ae3e8afd2ee487f4bea68eaff83d1/specifyweb/stored_queries/query_construct.py#L48)
^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 https://github.com/specify/specify7/blob/4e5722aabb4ae3e8afd2ee487f4bea68eaff83d1/specifyweb/stored_queries/query_construct.py#L56
This is one component of https://github.com/specify/specify7/issues/4640
Please see the issue for a more detailed write-up with additional considerations.