How to query from one model to another model ( Parent Relationship)

  • 1
  • Problem
  • Updated 4 years ago
  • Solved
I have two objects like Teacher and student and i created two models. 
I have created two tables with two models. I would like to search Teacher object with the student record. 
Photo of Arjun Arjun

Arjun Arjun

  • 230 Points 100 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Arjun,  this is very feasible.  I assume that there is some relationship between the two objects, maybe each student has a lookup to teacher. 

So,  make your two models.   But the teacher model should have the following items. 

1. Set model to Not load data on page load (in the advanced tab of the model)
2. Give it a condition on the Teacher Record Id that does not have any value and is "filterable default off" 

Then go to your Student Table and add a Row Action.   It should be of type "Run Multiple Actions".   Here are the actions you run. 
1. Activate Condition and Send value.  Look for the Teacher Model and select the condition you made in step 2 above.  Pass it the TeacherId value from your student record using merge syntax.  Probably somthing like {{TeacherId}}
2. Query model.  Choose the teacher model.  This will make your teacher table appear with the record associated with your student. 

If the relationship goes through a junction object (many to many) your teacher model needs to be set on that junction object and your condition should look for all Junction Object  records that have the particular student Id. 

Hope this provides you an outline of how to get this done.