problem with embedsMany and using the include filter on multiple levels

23 views
Skip to first unread message

Francois Laforge

unread,
Oct 12, 2016, 1:10:38 PM10/12/16
to loopb...@googlegroups.com
I have forked the loopback-example-relations repository for my example.

In the original repository we have a 'customer' model which embeds many 'email-addresses'.

I added a new relation to the email-address model which belongsTo an account. 

email-address.json
  "relations": {
    "account": {
      "type": "belongsTo",
      "model": "Account",
      "foreignKey": "accountId"
    }},


I know the example doesn't make much sense, I just wanted to use existing models in my example

so:

customer --> emails --> account

When I call the following API endpoint
/Customers/{id}/emails

with the following filter
{"include":"account"}

I get the result (account information is included)
[
 
{
   
"
label": "home",
   
"
address": "la...@yahoo.com",
   
"
id": "252269b9a4f55b8c6c725b2a",
   
"
accountId": "57fd44bbb9e3c793d68293d8",
   
"
name": "home",
   
"
account": {
     
"name": "Checking",
     
"balance": 5000,
     
"id": "57fd44bbb9e3c793d68293d8"
   
}

 
}

]



However, when I call the following endpoints
/Customers
/Customers/{id}

with the following filter:
{"include":{"emails":"account"}}

I get the following result (account information is not included)

{ "name": "Larry Smith", "id": "57fe689783b9acc04ea083d3", "emailList": [ { "label": "home", "address": "la...@yahoo.com", "id": "252269b9a4f55b8c6c725b2a", "accountId": "57fd44bbb9e3c793d68293d8", "name": "home" } ], "accountIds": [], "emails": [ { "label": "home", "address": "la...@yahoo.com", "id": "252269b9a4f55b8c6c725b2a", "accountId": "57fd44bbb9e3c793d68293d8", "name": "home" } ] }


 Question:  can the include filter "populate" sub-relations?  When calling customer, I would like to see the emails and the account within each email, but this is not currently the case.  Is this a bug that should be reported or by design?

Reply all
Reply to author
Forward
0 new messages