Search code examples
odatahana

XSODATA - get lists of objects having id of parent objects


I am thinking this is not possible but my understanding of odata is still in it's infancy. This is hana xsodata i am attempting to use.

Say I have a object Owner and object Dog. Dog has a field ownerID. The Owner object has a field called gender.

I want to get returned all Owners of gender female and all the dogs associated to those owners.

[
{ 
 Name: "Jessica",
 ID: 27,
 Gender: "female",
 Dogs: 
 [
  {
   name: "fido",
   age: 3,
   ownerID: 27
  },
  {
   name: "fluffy",
   age: 5,
   ownerID: 27
  } 
 ]
},
{ 
 Name: "Allison",
 ID: 5,
 Gender: "female",
 Dogs: 
 [
 {
  name: "doggie",
  age: 4,
  ownerID: 5
 },
 {
  name: "frank",
  age: 2,
  ownerID: 5
 } 
}
]

I am not sure what I can give as an example of what I have tried. i get easily get the list of owners. http:///crud.xsodata/owner?$filter=gender eq 'female'

i could use the results from that to get all the dogs http:///crud.xsodata/owner?$filter=ownerID eq '' or ownerID eq '' or ownerID ... and if i wanted to get the owner in the query i could expand on owner, though i would have owner duplicated and be a child of the dog. but i want the dogs as children of the owner.

I really was hoping to do this in one call. it seems like i need a reverse form of navigates? thanks for any help expanding my knowledge.


Solution

  • You can get that by using odata associations. In the xsodata, declare an association with "Owners" as principal entity and "Dogs" as dependent entity.

    Refer ODATA Association