Footprint and populate models are not working as expected
KNTH01 opened this issue · 0 comments
KNTH01 commented
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": "admin@admin.com",
"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": "admin@admin.com",
"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! :)