Skip to Content

How to navigate through multiple entities using xsodata?

Hi All,

Below are the tables that I'm trying to link/navigate through

Table 1 : mid.customer

Primary Key : customer_id

Table 2 : mid.product

Primary Key : product_id,id

Table 3 : mid.Item

Primary Key : id

Here the 3 tables are connected with the columns as below

1 ) purchased_product_id(table1) -> product_id(table 2)

2) id(table2) -> id(table 3)

So the output columns i need is customer_id(table 1), name(table 2) and type(table 3). I tried writing some xsodata associations to achieve this, but I was not able to extend beyond associations of two tables. Below is the code

"mid.customer" /* table 1*/
as "customer1" navigates ("customer_buy" as "purchase");

"mid.product" /* table 2*/
as "product1";

association "customer_buy" 
principal "customer1"("purchased_product_id") 
multiplicity "1" 
dependent "product1"("product_id") 
multiplicity "*";

How to extend the code so that I get the desired output columns? Please help.

tb1.png (4.4 kB)
tb2.png (5.5 kB)
tb3.png (4.4 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Feb 25, 2019 at 06:56 AM

    If you really just wanna have an additional association from table 2 to table 3 then just add it For instance:

    service {
      "mid.customer" /* table 1*/
      as "customer1" navigates ("customer_buy" as "purchase");
    
      "mid.product" /* table 2*/
      as "product1" navigates ("itemInfo" as "toItem");
      
      "mid.Item" /* table 3*/
      as "item";
    
    
      association "customer_buy" 
      principal "customer1"("purchased_product_id") 
      multiplicity "1" 
      dependent "product1"("product_id) 
      multiplicity "*";
      
      association "itemInfo"
      principal "product1"("id")
      multiplicity "1"
      dependent "type" ("id")
      multiplicity "1";
    }
    

    With that you are able to do a GET request on the customer1 entity getting the releated data from the product1 and item entity using an expand.

    ....xsodata/customer1?$format=json&$expand=purchase,purchase/toItem

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.