I'm trying to write a SOQL query that will retrieve a list of Content sObjects and return it's related child Attribute sObjects.
First I wrote the SOQL query to grab the parent records, and it returns the expected results:
SELECT cms__Name__c, cms__Published_Start_Date__c FROM cms__Content__c WHERE cms__Published_Start_Date__c <= 2017-03-22T18:14:26.128Z AND cms__Content_Type__r.Name = 'CT-000068' LIMIT 10
The problem comes when I try to add the inner query to select the Attribute records. The following is the same query with the addition of the inner query:
SELECT cms__Name__c, cms__Published_Start_Date__c, (SELECT cms__Name__c, cms__Value__c, cms__Type__c, cms__Language__c from cms__Attribute__r) FROM cms__Content__c WHERE cms__Published_Start_Date__c <= 2017-03-22T18:14:26.128Z AND cms__Content_Type__r.Name = 'CT-000068' LIMIT 10
You'll notice I am querying on the relationship in the inner query, denoted by use of cms__Attribute__r. I've confirmed in workbench this is in fact the name of the relationship:
So what's going on here? I would expect that this would return me a List of Content records, each record with their child list of Attribute records.
Thinking maybe developer console just wasn't smart enough to visually display a 1:M relationship, I tried to run the query in my APEX code as well, but no luck.
Here's the full exception I've received:
cms__Type__c, cms__Language__c from cms__Attribute__r) FROM cms__Content__c ^
ERROR at Row:1:Column:125 Didn't understand relationship 'cms__Attribute__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
I believe I did - what else am I missing?