function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SF_MonkeySF_Monkey 

iterate child records with aura:component

I am tring to load the child records with aura iterate. The records are loading from soql statement and the parent records are displayed; however, the child records will not load. It is a self-lookup relation with the object.
<section >
          	    
            <div >
                         
        <div class="slds-modal__content slds-p-around_medium" >
            <lightning:accordion allowMultipleSectionsOpen="true" >   
            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer ">
        <div aura:id="conEditForm">
        <thead>          
            <tr class="slds-text-heading--small"> 
                <th scope="col"><span class="slds-truncate">Name</span></th>
                <th scope="col"><span class="slds-truncate">Location Name</span></th>
                <th scope="col"><span class="slds-truncate">Login</span></th>
                <th scope="col"><span class="slds-truncate">Password</span></th>
                <th scope="col"><span class="slds-truncate" style="width:75px">Portal URL</span></th>
                <th scope="col"><span class="slds-truncate">Active</span></th>
                <th scope="col"><span class="slds-truncate">Monitored</span></th> 
                <th scope="col"><span class="slds-truncate">Online Access</span></th> 
                <th scope="col"><span class="slds-truncate">Last Download</span></th>
                <th scope="col"><span class="slds-truncate">Action</span></th>
                <th scope="col"><span class="slds-truncate">Record</span></th>
            </tr>
            
        </thead>
        <tbody >
            <aura:iteration items="{!v.data}" var="vend" indexVar="rowIndex">
                <tr>
                   
                    <th scope="row" data-index="{!rowIndex}" onclick="{!c.toggle}" role="gridcell">
                        <lightning:accordionSection label="{!vend.Name}" /></th>  
                    <td><ui:outputText value="{!vend.Location_Name__c}"/></td>                    
                    <td><ui:outputText value="{!vend.Login__c}"/></td>                
                    <td><ui:outputText value="{!vend.Password__c}"/></td>
                    <td><ui:outputText value="{!vend.Portal_URL__c}"/> </td>  
                    <td><ui:outputCheckbox value="{!vend.Active_Account__c}"/></td>
                    <td><ui:outputCheckbox value="{!vend.X180_Monitored__c}"/></td>
                    <td><ui:outputCheckbox value="{!vend.Online_Access__c}"/></td>
                    <td><ui:outputDate value="{!vend.Last_Download__c}"/></td>
                    <td><button type="button" onclick="{!c.handleRowAction}" class="slds-button slds-button--neutral slds-float_center"  id="{!vend.Id}">Add Child</button></td>
                    <td><a href="{!'/one/one.app?#/sObject/'+ vend.Id + '/view'}"><ui:outputText value="Record Detail"/> </a></td>
                </tr>
       
                <!--Expanded section to display the child vendor invoices -->
                                           <aura:if isTrue="{!vend.expanded}">
                    
                    
                    <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer ">
                     <thead>          
            <tr class="slds-text-body_small "> 
                <th scope="col" style="width:50px"><span class="slds-truncate">Account #</span></th>
                <th scope="col" style="width:75px"><span class="slds-truncate">Service Type</span></th>
                <th scope="col" style="width:75px"><span class="slds-truncate">Aggregate Benchmark</span></th>
                <th scope="col" style="width:75px"><span class="slds-truncate">Location Name</span></th>
            </tr>
            
        </thead>
                		<aura:iteration items="{!vend.vendor_invoices__r}" var="chil">            
        <tbody>
                       
                <tr>
                   
                    <th scope="row" ><ui:outputText value="{!chil.Name}"/></th>
                    <td ><ui:outputText value="{!chil.Service_Type__c}"/></td>               
                    <td style="width:75px"><ui:outputCurrency value="{!chil.Aggregate_Benchmark__c}"/></td>
                    <td style="width:75px"><ui:outputText value="{!chil.Location_Name__c}"/></td>
                </tr>
            
            
        </tbody>
         </aura:iteration>    
    </table>
                   
                </aura:if>
                     </aura:iteration>
        </tbody>
                 </div>
    </table>
            </lightning:accordion>
                </div>
  
            </div>
        </section>

Any help would be appreciated
Ramesh DRamesh D
@sf_Monkey,
Change this from 
<aura:iteration items="{!vend.vendor_invoices__r}" var="chil">
to
<aura:iteration items="{!vend.vendor_invoices__c}" var="chil">

and try, let me know if it works
 
Raj VakatiRaj Vakati
You are doing correct and can you check the Relationship api name?

for example, the below code is working 

https://developer.salesforce.com/forums/?id=9060G000000XdAfQAK
 
<aura:component controller="accountsWithContactsClass" implements="flexipage:availableForAllPageTypes" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
    <aura:attribute name="accounts" type="Account[]" />
    <table>
        <tr>
            <td>
                <b>Name</b>
            </td>
            <td>
                <b>Industry</b>
            </td>
            <td>
                <b>Contacts</b>
            </td>
        </tr>
        <aura:iteration items="{!v.accounts}" var="accs1" >
            <tr>  
                <td> {!accs1.Name}  </td>
                  <td> {!accs1.Industry}  </td>
                 <!--   <td>   {!accs1.Contacts.lastName}  </td> -->
                <table>
                    <aura:iteration items="{!accs1.Contacts}" var="con1" >
                        <tr>
                            <td>{!con1.LastName}</td>
                        </tr>
                    </aura:iteration>
                </table>
            </tr> 
         </aura:iteration>                                           
    </table>    
</aura:component>

 
SF_MonkeySF_Monkey
@rajVakati the relationship name is vendor_invoices__r. That is what i am using for the soql query in the apex controller and that query is pulling the correct records. 
Child Relationship Name: Vendor_Invoices
soql query:
select id, account__c, Name, Portal_URL__c, login__c, password__c, Location_Name__c,X180_Monitored__c, Active_Account__c, Online_Access__c, Last_Download__c, Vendor_Information__c,
                                           (select name, Service_Type__c, Location_Name__c, Aggregate_Benchmark__c from vendor_invoices__r)
                                           from vendor_invoice__c where (account__c = :accId AND recordtypeid = :recId)

The records are coming but only child records are not being displayed

@rameshDeepaish i have tried that and other variation of that but it is still not displaying those records
Jaap van der MolenJaap van der Molen
@SF_Mokey ever figured this out? I am running into the same issue