Get a list of kids based on the grandparent

Options
Ok it's a bit weird but it is a good metaphore of what I am facing now. 

Let's say you have a nested database like this :
grandparent -> parents -> children. 

How would you configure your endpoints so that by inputing a grandparent you have it's grandchildren. 

Should I use addons ? Or is it another way to do this ? If yes which one is the best regarding app performance ? 

Comments

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options
    Hey, Robin! Addons would be what you want here.
  • Robin C
    Robin C Member
    Options
     Actually not really, is there a way to query all grandchildren which father's father is a particular data ? 

    My case is an app with cities -> shops -> products. If I want to query all the products of a certain city, I am forced to GET a city, in which i GET all the shops, in which i GET all the products. 

    And this cause 2 problems : 
    • First, I am almost sure that it is not super effective
    • All my products are getting ordered by shops as I am not directly getting the products but the city they are in 


    What do you think ? Can't I do something with joins or custom query ? 
  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options
     You should be able to accomplish this with joins and a custom query as well. Going off of your original example, what I have here is a database structure where the children table has a reference to the parent table, and the parent table has a reference to the grandparent table.[image.png]So, if we then query all records from the children table as grandchildren, we can use joins to create that link between the children table and the parent table, and then the parent table to the grandparent table, and finally use a custom query along with our input to get our response.
    [image.png]
  • Robin C
    Robin C Member
    Options
     Wow thank you very much, it is exactly what I was searching for ! You made my day !