I have a many-to many relationship between three objects. LGFProducts, PartsinProducts, and Parts. PartsinProducts is the junction object. I want to be able to get data like the names of the parts that are related to the selected LGFProduct.
I understand that parent-child relationship can only traverse one level down while grandchild-grandpa can travel 5 levels at most. What is the parent-child or child-parent in a many-to-many relationship?
I assumed that I should be traversing upwards from Parts to the junction object partsinproduct and then LGFProducts? But my friend who is not a Salesforce expert but has knowledge in CS said that I should do a parent-child query (of LGFProducts to partsinproduct) to child-parent relationship query (PartsinProduct to Parts). Or perhaps both of these options are wrong and another is appropriate.
Also, I am having a little trouble traversing for custom objects. I understand that I need to append the letter r instead of c but get confused. For example, this is my attempt at a three level upward traversal that fails.
SELECT Id, Name, Parts__r.PartsinProducts__r,LGFProducts__r.Name
FROM Parts__c
Also if three levels of upward traversal are needed, could one provide an example with custom relationships? As seen above, I am having difficulty successfully querying a three level upward traversal statement for custom objects.
This is my attempt at the parent-child relationship query of LGFProduct to PartsinProducts:
SELECT Name,
(
SELECT Name
FROM PartsinProduct__r
)
FROM LGFProduct__c
I am then given this error: