cancel
Showing results for 
Search instead for 
Did you mean: 

How to navigate through multiple entities using xsodata?

former_member594414
Participant
0 Kudos

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.

pfefferf
Active Contributor
0 Kudos

What is your goal? To define an additional navigation/association from your table 2 to table 3 or to have all 3 required fields on one level (aka in one entity type)?

former_member594414
Participant
0 Kudos

I need to define an additional association from table 2 to table 3. To put it straight, I need all the three tables to be associated and navigated so that when I use $expand in uri, I should be seeing the data of all 3 tables together

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

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

Answers (0)