[!example]+ Query 2: ‘Preferred Taxon’ fields first
If I reverse the order and put Preferred Taxon - Genus before Taxon - Genus, both columns return “Cambarunio”.
Again, Taxon and Preferred Taxon values should differ for Genus, but instead both columns are taking the value of whichever field was first in the query.
[!example]+ Query 3: Forcing the relationship through ‘Taxon’
I also tried going through Taxon and then to Preferred Taxon, e.g., Taxon(any rank)Preferred Taxon
The Is Preferred values are correct, which suggests the query running on the backend can recognize both levels at the same time, but it conflagrates the return of Taxon and Preferred Taxon values and thus truncating the column header in the results to just Genus or Species.
The ‘Preferred Taxon’ shows correctly when rendered alongside ‘Taxon’ on the CO form, so I’m thinking it must be an issue with the query builder itself.
Is there something I am doing wrong with my query or is it a bug?
You are correct in that the issue is related to the Query Builder rather than your data. This is a bug related to issue #8560 on GitHub. I left a comment on the issue to let the developers know you encountered it! The bug leads to unexpected behaviors, like what you’ve described, when a query includes tree rank mappings through multiple relationships such as Taxon and Preferred Taxon. It was fixed in 7.12.1.1, but the resolution introduced more critical issues involving the query builder, so it was reversed in 7.12.1.2. I will explain a potential workaround for your query, but it may or may not be valuable for your use case since it changes how the results are organized.
The inclusion of a tree rank is what causes the problem, so it will not occur if you exclude ranks from the query. You can try using the (any rank), Parent, and Child relationships instead. Rather than searching for related records in a certain rank, the Parent and Child relationships search directly for the parent or child of the Taxon record used in the determination. Then, you can search for the parent of the parent, and so on, to search as far up the taxon tree as you want.
Keep in mind that since the Parent/Child relationships depend on the rank directly above/below the Taxon used in the determination rather than the rank defined in the query, the values in those columns will not always belong to the same rank. In the image below, record 000043577 is determined to a record at the Genus level. Record 000043578 is determined to a record at the Subspecies level. You can use the treeDefItem relationship to show you the rank name if needed, as shown in the image below.