Anyone found a way to select parent fields with force:recordData?
It would be great to have something like this:
<force:recordData recordId="{!v.recordId}" targetRecord="{!v.child}"
layoutType="FULL" fields="parent__r.Name" recordUpdated="{!c.init}" />
init: function(cmp, evt, helper) {
var child= cmp.get("v.child");
if(child) {
console.log(child.fields.parent__r.Name);
}
}
results is undefined
Best Answer
So with some help I figured out that it works, it is just a bit dirty to get the values, this is the path through the object structure:
So the
targetFields
attribute on recordData just came to my mind, and I replacedtargetRecord
. Now it works as expected:Notes:
parent__r.Name
andparent__r.Id
will ALWAYS be part of the data setMY_NAMESPACE__parent__r.MY_NAMESPACE__foo__c
The max depth is 5
parent__r.parent2__r.parent3__r.parent4__r.parent5__r.bar__c
Exceeding the limit will silently fail and leave your
targetFields="{!v.child}"
nullSame as when you mistype field names in the
fields=""
attribute (or forgot the NS) it will tell you the miss-leading error message:Edit
Found it officially documented, hidden in the Lightning Components Developer Guide: