finale
finale copied to clipboard
PUT does not update associated tables
This issue was copied from the epilogue issues and is, obviously, still a problem in finale.
I'm trying to use PUT
to update a model with associations.
I have a Map
model which HasMany Layers
. Map 4 has one layer in the DB. map.json
specifies two layers.
When I use PUT
to update map 4, the request succeeds and returns a modified Map:
$ http PUT localhost:1337/object/map/4 < map.json
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 514
Content-Type: application/json; charset=utf-8
Date: Tue, 01 Nov 2016 19:03:54 GMT
ETag: W/"202-avvKiF6AQG/hPzW3CJAakQ"
X-Powered-By: Express
{
"author": "danvk",
"baseMapStyle": "{}",
"createdAt": "2016-11-01T16:05:30.086Z",
"description": "This map has two layers",
"id": 4,
"lat": 43.22,
"layer": [
{
"config": "config = {}",
"description": "It's a really great layer, trust me.",
"name": "My layer",
"sqlQuery": "SELECT * FROM dataset",
"zIndex": 0
},
{
"config": "config = {}",
"description": "It's an even better layer, trust me.",
"name": "My layer",
"sqlQuery": "SELECT * FROM dataset",
"zIndex": 1
}
],
"lng": -137.22,
"name": "My Map",
"updatedAt": "2016-11-01T19:03:54.447Z",
"zoomLevel": 12
}
A subsequent GET, however, shows that the new data wasn't written to the database:
$ http GET localhost:1337/object/map/4
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 744
Content-Type: application/json; charset=utf-8
Date: Tue, 01 Nov 2016 19:12:39 GMT
ETag: W/"2e8-bsUeBJOAcTqI1e8ugkbqpg"
X-Powered-By: Express
{
"author": "danvk",
"baseMapStyle": "{}",
"createdAt": "2016-11-01T16:05:30.086Z",
"description": "This map has two layers",
"id": 4,
"lat": 43.22,
"layer": [
{
"SavedMapId": 4,
"createdAt": "2016-11-01T16:05:30.123Z",
"description": null,
"id": 3,
"name": "Untitled Layer",
"sqlQuery": "SELECT *\nFROM blah",
"updatedAt": "2016-11-01T16:05:30.123Z",
"zIndex": 1
}
],
"lng": -137.22,
"name": "My Map",
"updatedAt": "2016-11-01T19:03:54.447Z",
"zoomLevel": 12
}
I'm running from HEAD using Postgres.
It would help to know how your models are defined and the contents of map.json
I just copied that issue from another post in epilogue. That really isn't my example. So, I just created a very simple test case to demonstrate this and I will try to provide enough information as to be duplicated.
First, here are the Sequelize models:
parent = this.sequelize.define('parent', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV1,
primaryKey: true
},
name: Sequelize.STRING
},{
timestamps: false
});
kid = this.sequelize.define('kid', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV1,
primaryKey: true
},
name: Sequelize.STRING
},{
timestamps: false
});
this.parent.hasMany(this.kid);
Here is the Finale resource
var parentResource = finale.resource({
model: parent,
endpoints: ['/parents', '/parents/:id'],
actions: ['create', 'update', 'list', 'read'],
include: [{
model: kid
}],
});
When the following object is POST
ed to /parents
, then parent and two kid records are created as expected.
{
"name":"daddy",
"kids": [
{
"name":"Steve"
},
{
"name":"Susie"
}
]
}
When the following object is PUT
to /parents/017c9090-ca4e-11e7-bd66-774ee4225968
("Steve" changed to "Stephen", the same object is returned in the message body as if the data was updated. However, subsequent GETs (and looking at the database) show that the update didn't occur.
{
"id": "017c9090-ca4e-11e7-bd66-774ee4225968",
"name": "daddy",
"kids": [
{
"id": "017c9091-ca4e-11e7-bd66-774ee4225968",
"name": "Stephen",
"parentId": "017c9090-ca4e-11e7-bd66-774ee4225968"
},
{
"id": "017c9092-ca4e-11e7-bd66-774ee4225968",
"name": "Susie",
"parentId": "017c9090-ca4e-11e7-bd66-774ee4225968"
}
]
}
Viewing the debug log output by Sequelize, shows that no UPDATE
statement was executed.
I don't think Sequelize supports this, so it looks to me like the only confusion happening is the return value from the PUT. https://github.com/sequelize/sequelize/issues/5240
Whoever looks into this deeper should probably figure out first how Sequelize itself handles this without finale and then decide how we want finale to handle this case.
I have the same issue. Does anybody have a solution for that?
PUT with associated models is still not working
Sequelize doesn't support this behaviour, so it's unlikely to be added anytime soon.