I have Custom Metadata types with simple relationships between them. When I query them with a relationship query and try to ORDER BY, only 1 of the inner records is returned.
I run this in Anonymous Apex:
Id tmp = ''; // This is populated, I'm just not putting it here
List<Parent__mdt> tmpList = [SELECT Id, MasterLabel, Custom_Order__c, Super__c,
(SELECT Id, MasterLabel, Custom_Order__c,
FROM Childs__r)
FROM Parent__mdt
WHERE Super__c = :tmp
ORDER BY Custom_Order__c ASC NULLS FIRST];
System.debug(tmpList[0].Childs__r.size());
...and I correctly see that there are 36 'Child' metadata records within that Parent. However, running the same code with an ORDER BY in the relationship clause:
Id tmp = ''; // Again, this is populated
List<Parent__mdt> tmpList = [SELECT Id, MasterLabel, Custom_Order__c, Super__c,
(SELECT Id, MasterLabel, Custom_Order__c,
FROM Childs__r
ORDER BY Custom_Order__c)
FROM Parent__mdt
WHERE Super__c = :tmp
ORDER BY Custom_Order__c ASC NULLS FIRST];
System.debug(tmpList[0].Childs__r.size());
...returns only 1 'Child' within the Parent.
Is this documented anywhere? Is there a way around this?