Strange behavior with embedded models (embedsOne --> embedsMany)

57 views
Skip to first unread message

Fadi Chalfoun

unread,
Sep 30, 2015, 12:30:17 PM9/30/15
to loopb...@googlegroups.com
I am encountering a strange behavior accessing embedded models. It might be the way I am structuring things but basically I have a model with an "embedsOne" relation and that model that is embedded has an "embedsMany" relation.

I have successfully created the "embedsOne" model and added a single record to that model's "embedsMany" collection.

User:
"relations": {
    "provider": {
      "type": "embedsOne",
      "model": "Provider",
      "property": "providerAccount",
      "options": {
        "validate": true,
        "forceId": false
      }
    }
  }

Provider:
"relations": {
    "allRatings": {
      "type": "embedsMany",
      "model": "Rating",
      "property": "allUserRatings",
      "options": {
        "forceId": false,
        "validate": true
      }
    }
  }

GET 


RESULT

[
  {
    "rating": 4,
    "comment": "This rocks!!",
    "username": "Jack",
    "userId": 1,
    "id": 1
  }
]

However, when I do a COUNT:

GET


RESULT

{
  "count": 0 <--- count is zero!
}


I'm a bit confused as to why this is happening, seems like I should be getting consistent results through these different APIs based on the model.

rites...@anthropower.in

unread,
Oct 2, 2015, 12:37:48 PM10/2/15
to LoopbackJS
I think you are experiencing the issue that I had posted here https://groups.google.com/d/msg/loopbackjs/YyFXDDyOCQw/K3moL3MiBAAJ


Alternate: Get all embedded items and use .length to count.

Fadi Chalfoun

unread,
Oct 20, 2015, 4:29:34 PM10/20/15
to loopb...@googlegroups.com
Thanks for the response, I also opened an issue which brings up that problem and a few others related to embedded models here: https://github.com/strongloop/loopback-datasource-juggler/issues/727. Seems that embedded models implementation is still fairly incomplete in Loopback unfortunately.

Reply all
Reply to author
Forward
0 new messages