Condition on child object from parent object model
we have a custom parent object and attachment as a child object. we have one reference field which is the parentId of attachment. when we try to add a condition to look for the parentId on the reference field then it is not working. where clause is not getting added to the attachment query
1
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
we have two models "checkInRecords" and "CheckIn". we are applying the child relationship condition on attachment object in "CheckIn" model. For parentId conditions, we are providing values from "checkInRecords" model. which is sequentially up from "CheckIn" model.
Below are the screenshots.
The query generated after page load having no conditions in attachments: SELECT CreatedDate,Check_Out__r.CreatedDate,Check_Out__r.Id,(SELECT Name,Parent.Id,Id FROM Attachments LIMIT 10),Check_Out__c,Check_Out__r.Name,(SELECT Body,ParentId,Id FROM Notes LIMIT 10),Id,CurrencyIsoCode FROM Participant_Check_In_Out_History__c WHERE (Id in ('a3pg00000006t4dAAA','a3pg00000006t3VAAQ','a3pg00000006sjoAAA','a3pg00000006sjQAAQ','a3pg00000006sjZAAQ','a3pg00000006sjPAAQ','a3pg00000006silAAA','a3pg00000006shiAAA','a3pg00000006shYAAQ','a3pg00000006shOAAQ','a3pg00000006sQ8AAI','a3pg00000006sPPAAY','a3pg00000006p6nAAA','a3pg00000006oxzAAA','a3pg00000006RjLAAU','a3pg00000005tcYAAQ')) ORDER BY CreatedDate DESC LIMIT 51
please do let me know if you need more details
Thanks
If checkinRecords is a parent to Checkin. And you want to limit the attachments under checkin - I don't believe you need any conditions on the child relationship. We're automatically going to associate the attachments with the appropriate Checkin record. And it can only associated with one "chekinRecords" record.
But I'm sure I'm missing somthing.
What we might be missing is the conditions on the child relationship of Check_Out__c in the CheckinRecords model.