You need to sign in to do that
Don't have an account?
mbudzyn
Lightning Component not rendering related fields
I'm new to Lightning components and am experimenting with my first app displaying a list of records from a custom object (Aircraft_Relationship__c); each record will include fields from two other related objects (master-detail to Aircraft__c and lookup to Account (field is Account is Aircraft_User__c). The listing of the primary object (Aircraft_Relationship__c) works fine.
For the life of me I cannot figure out why when I launch the app the related fields do not appear; I've reviewed the documentation and from what I understand the dot notation is supposed to work in traversing these relationships (as I'm familiar with in VF).
Any help would be appreciated (am I missing something obvious?)
Hre's Apex controller pulling the related fields:
For the life of me I cannot figure out why when I launch the app the related fields do not appear; I've reviewed the documentation and from what I understand the dot notation is supposed to work in traversing these relationships (as I'm familiar with in VF).
Any help would be appreciated (am I missing something obvious?)
Hre's Apex controller pulling the related fields:
public with sharing class auraAClisting { @AuraEnabled public static List<Aircraft_Relationship__c> findAll() { return [SELECT id, name,status__c,ownership__c,Aircraft__r.name,aircraft__r.id,New_Used__c,Model__c,Aircraft_User__c,Aircraft_User__r.name,Owner__c,Owner__r.name FROM Aircraft_Relationship__c where status__c = 'Delivered' LIMIT 50]; } }Here's the client-side controller:
({ doInit : function(component, event) { var action = component.get("c.findAll"); action.setCallback(this, function(a) { component.set("v.acr", a.getReturnValue()); }); $A.enqueueAction(action); } })And the component:
<aura:component controller="auraAClisting"> <aura:attribute name="acr" type="Aircraft_Relationship__c[]"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <ul class="list-group"> <aura:iteration items="{!v.acr}" var="ac"> <li class="list-group-item"> <a href="{! '/' + ac.Id }"> <p>{!ac.Name}</p> <-- DISPLAYS VALUE in APP <p>{!ac.Aircraft__c}</p> <-- DISPLAYS VALUE in APP <p>{!ac.Aircraft__r.id}</p> <-- NOTHING APPEARS in APP </a> </li> </aura:iteration> </ul> </aura:component>
All Answers
1) run the query in regular non-lightning mode to confirm the query work as expected.
2) Did you get the same result using {!ac.Aircraft__r.Name}? Does it return blanks too? In theory it should be the same as {!ac.Aircraft__c}
Thx
Regarding your #2--yes, the behavior is the same for any of the related fields--nothing returns in the app:
Regarding your #1:
Query appears to be working fine; here's what I did in Execute Anonymous: Here's the resulting debug lines (most of the debug log omitted for clarity)--and the related fields are being returned: What I didn't post yet is the running app; here's a screen cap of what it's returning:
try removing everything and leaving the id and see what is displayed.
by does the link work(does it take you to the detail page)? <a href="{! '/' + ac.Id }">
thx
<p>{!ac.Aircraft__c}</p>
But not for:
<p>{!ac.Aircraft__r.id}</p>
I would expect the id to appear twice, but it does not for the latter line.
(and yes, the link works).
I've been working on this for a few days and I've simplified the problem down; I really want a number of related fields to appear on the listing, not just the Id field. I'm using {!ac.Aircraft__r.id} to test if I can get at least one related field to show up on the listing.
I see, you set the attribute before the handler/initialization in your component.
Typically the handler goes first then the attribute.
thx.
<aura:attribute name="acr" type="Aircraft_Relationship__c[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
I'm having the same issue you were, but am unsure of the case I should be using to ensure this works. What was your solution in the end? I feel like I'm matching cases correctly, but clearly have something wrong?
Andy
I see clearly id should have been Id because JS case sensitivity.
I'm having same kind issue. Case is all good. when I check in Console.log __r field is properly populated. But same name in mark up doesn't show up the value.
Any help on this please.
https://salesforce.stackexchange.com/questions/193501/displaying-related-records-in-lightning/193507#193507
I have the query:
APEX
List<Property_Contact_Roles__c> ret = [select name, property__r.name, property__r.market__c,
property__r.region__c from Property_Contact_Roles__c limit 5];
AURA
<aura:iteration items="{!v.retProperties}" var="prop" indexVar="index">
</a></div>
<tr>
(DOESN'T WORK) Region: {!prop.property__r.region__c}
</tr>
<tr>
(WORKS) Region: {!prop.Property__r.Region__c}
</tr>
</div>
</a>
I do not know why it has to be in this format, because the query is obviously not formatted like so, but the first letter has to be capitalized.
Hope this helps.