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
json array becomes key of json object (and fails to parse) #315
Comments
Assuming you're on the latest, if you do: queryChain.on('query', function(data) {
console.log(data.sql);
console.log(data.bindings);
}).then(function() {
// ...
}); you should see the data that will be passed off for the query. |
Also, judging from the output there, it looks like maybe the JSON is already stringified rather than in object form? |
Query:
Bindings:
I'm assuming that the statement and bindings are what you're passing directly to |
Oh, indeed it is. See brianc/node-postgres#442, brianc/node-postgres#374, bookshelf/bookshelf#94 So I think it looks like pre-stringifying the data will do the trick? |
I tried stringifying and it didn't work, so I tried wrapping in an object and I discovered this strange behavior with Here's what I've got: Models.Customer = PostgreSql.Model.extend({
parse: function (obj) {
if ('creditcards' in obj) {
obj.creditcards = obj.creditcards.dummy || [];
}
console.log('parse Customer', obj);
return obj;
}
, format: function (obj) {
if ('creditcards' in obj) {
obj.creditcards = { dummy: obj.creditcards || [] };
}
console.log('format Customer', obj);
return obj;
}
}); However, |
Pretty sure that was a regression added here: bookshelf/bookshelf#377 Just fixed it and cut 0.7.2 - see if that gets you what you're looking for. |
It's close but does'nt work, is in my model I send array of json , I have 'error syntax' |
Hi @CaptainJojo. Can you please open this as a new issue including code that generates the error, and pass |
Any updates on this one? My case
does
that ends up as
|
Anyhow stringify before save does the trick. |
There is a json field
cards
that contains an array. When the model serializes it serializes the array as the key to an object with no value and causes a parse error:This error is actually from the
pg
library, so maybe the problem is actually there. How would I see the SQL right before it's handed off topg
?The text was updated successfully, but these errors were encountered: