Skip to content

Encountered several problems trying to work with Embedded Models (sample repo provided) #727

Closed

Description

@vanraizen

There are a few issues that I would like to bring to attention here:

Note: I am referencing https://docs.strongloop.com/display/public/LB/Embedded+models+and+relations

  1. Code does not adhere to Embedded objects defined with "forceId": false and ids are created anyways.
  2. From the link above, for EmbedsOne the "Helper methods" section defines methods that do not exist: customer.address.create() and customer.address.update()
  3. From the link above, for EmbedsMany the "Helper methods" section defines methods that do not exist: customer.emails.add()
  4. updateAttributes is available as a function on an EmbedsMany relation even though this is not listed in the documentation
  5. API count on EmbedsMany method always returns 0:
    http://localhost:3000/api/providers/1/allRatings/ <-- returns an array with 2 objects:
    http://localhost:3000/api/providers/1/allRatings/count <-- returns: { "count": 0 }
  6. Successive calls to model.save() with an EmbedsOne model after calling create() on an EmbedsMany within the EmbedsOne model triggers a duplicate key issue. Only way to solve problem is to manually call unsetAttribute('id'). (See function addRating() and lines 67-72 in /server/boot/data-preload.js to see what I mean)

The sandbox repo is located here: https://github.com/vanraizen/loopback-embedded-sandbox

The main demonstration code is located here: https://github.com/vanraizen/loopback-embedded-sandbox/blob/master/server/boot/data-preload.js

To run the sample code: "node server/server.js" and look at output

Activity

  1. self-assigned this
    on May 31, 2016
  2. loay commented on May 31, 2016

    @loay
    Contributor

    Thanks. I am having a look.

  3. dpasqualin commented on Oct 29, 2016

    @dpasqualin

    I'm having a hard time trying to understand the "embeds" feature through the official documentation. I believe @vanraizen contribution can help with that. I intend to use loopback in production, but I saw many old issues like this, still with no solution. What should I expected for the future of loopback? Thanks.

  4. removed their assignment
    on Nov 21, 2016
  5. jhonasn commented on Dec 9, 2016

    @jhonasn

    I'm having the same "count" problem. The filter is not working either. I think that we need to use just the standard old relational relations to continue using strongloop without problems. That's what i'm going to do for now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions