I have a model User defined as:
{
...
phone: {
type: 'string',
columnName: 'ph'
},
prefer_ship_address: {
type: 'json',
columnName: 'ps'
},
...
}
When I try to update prefer_ship_address, I find the key name 'phone' inside the value of the prefer_ship_address is replaced by 'ph'. For example, if I update prefer_ship_address with value
{
name: 'foo',
address: 'bar',
phone: '11111111111'
}
, then I print input values of update function in the adapter
{
updatedAt: Mon Feb 22 2016 14:25:32 GMT-0600 (CST),
ps:
{
name: 'foo',
address: 'bar',
ph: '1111111111'
}
}
looks like an adapter problem,which one do you use?
@atiertant I use my own adapter. But I don't think this is an adapter problem, because I print out values at the first line in the update function. That means adapter has not done anything yet to values which is passed by waterline.
update: function(connectionName, collectionName, options, values, cb) {
console.log(values);
...
}
Looks like it's recursively replacing instances of phone with the column name. Could you post the update query you are using or create a repo with the models and a route that re-creates the issue?
@particlebanana Here is the update query.
sails.models.user.update(
{
where: {
uid: 'xxxxxxx'
}
},
{
prefer_ship_address:
{
name: 'foo',
address: 'bar',
phone: '11111111111'
}
});
@Bangsheng i think offshore PR-17 should correct this. could you test with current offshore master branch ?
@atiertant I tested with [email protected] and the problem was not solved.
@Bangsheng the fix is not in [email protected] only on git for now. could you replace your offshore/lib/offshore/core/transformations.js with this one transformations.js?
@atiertant Yes! Problem Solved. Looks like function recursiveParse inside Transformation.prototype.serialize needs some changes. Brilliant! Thanks!
Wow, this is breaking out data in production!
@particlebanana : Simple repo with reproduction https://github.com/wulfsolter/waterline-issue-json-attributes-changing
Current workaround is use the Offshore transformations.js linked above.
PR to fix by backporting Offshore's MIT licenced code https://github.com/balderdashy/waterline/pull/1390
@wulfsolter @Bangsheng @athieriot @particlebanana Hey everyone, we're currently moving all the Waterline cases to Sails for Github issues. I see this one was potentially resolved with a patch to Waterline at the time. I appreciate the efforts! Feel free to update us if anything remains of the issue. Thanks!
This has been published.