Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Footprint and populate models are not working as expected #15

Open
KNTH01 opened this issue Jun 5, 2016 · 0 comments
Open

Footprint and populate models are not working as expected #15

KNTH01 opened this issue Jun 5, 2016 · 0 comments

Comments

@KNTH01
Copy link

KNTH01 commented Jun 5, 2016

Hi,

I am not sure if this is a bug, or if this works as designed.

I use trailpack-waterline for my ORM and mongodb.

Here is my footprints.js :

  models: {
    options: {
      /**
       * Whether to populate all model associations by default (for "find")
       */
      populate: true
    },

Then, when I perform a GET request :

GET /user HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: c2680799-ac9a-b0ef-be1d-2a9222303881
{
    "address": "5754340ddd1aa8442a6df9e9",
    "email": "[email protected]",
    "firstName": "Kevin",
    "lastName": "Nguyen",
    "createdAt": "2016-05-29T14:01:02.953Z",
    "updatedAt": "2016-06-05T14:15:41.832Z",
    "id": "574af61e0d08d6a23108467f"
  },

The address attribute is not populated as I expect. I have to make this request to have my attribute populated :

GET /user?populate=address HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 405fcb38-41f4-ae1c-f9ed-f223f14ea46c
  {
    "address": {
      "streetAddress": "1360 route des Dolines",
      "zipCode": "06560",
      "city": "Sophia-Antipolis",
      "createdAt": "2016-06-05T14:15:41.822Z",
      "updatedAt": "2016-06-05T14:15:41.822Z",
      "id": "5754340ddd1aa8442a6df9e9"
    },
    "email": "[email protected]",
    "firstName": "Kevin",
    "lastName": "Nguyen",
    "createdAt": "2016-05-29T14:01:02.953Z",
    "updatedAt": "2016-06-05T14:15:41.832Z",
    "id": "574af61e0d08d6a23108467f"
  },

So the question is : What if I have many attributes I want to populate in the GET request ?

I also have another question :

In my client, I want to perform an update on a user, and this is working, although I am surprised :

this.$http({
      url: `/user/${user.id}`,
      method: 'PUT',
      data: {
        firstName: user.firstName,
        lastName: user.lastName,
        address: {
          streetAddress: user.address.streetAddress,
          zipCode: user.address.zipCode,
          city: user.address.city
        }
      }
    })

Trails response on a PUT request gives me a user but the address attribute is still not populated. BTW, the address field is well updated.

Thanks for explaining me how this works! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant