So I am trying to do an odd fetch. I have a donation record that when created takes a snapshot of a n-n type relationship of the related person. So when I query asking for X values of that related type record it returns duplicate donations if the person has multiple types that fall under that X. Putting distinct=true in the top record of course works but I don't want thousands of records back, I want to run an aggregate. So adding an ID attribute with a count aggregate and distinct tag. This didn't work since I believe it applies the attribute distinct before linking with the type and applies the overall fetch distinct after the aggregate. So is there a way to apply distinct after the linking but before the aggregate runs?
<fetch distinct="true" aggregate="true" >
<entity name="contributiondonor" >
<attribute name="amount" alias="amount" aggregate="sum" />
<attribute distinct="true" name="contributionnumber" alias="contributionnumber" aggregate="count" />
<link-entity name="contributiondonor_constituent" from="contributiondonorid" to="contributiondonorid
<link-entity name="constituenttype" from="constituenttypeid" to="constituenttypeid" link-type="inner" alias="constituenttype" >
<filter type="and" >
<condition attribute="specgroup" operator="in" >
<value>344220011</value>
<value>344220010</value>
</condition>
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>