-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Working for updates? #25
Comments
@juandiegopalomino Hey! The update queries are included on the test suite, Can you please provide a code snippet of your model method call and the thrown error? Also, what Bookshelf & Knex versions are you using? |
@ricardogama Hi there, We're currently using bookshelf v0.9.45 and knex v0.11.9 |
I have this exact same problem. Could it be emitting a different event because of the |
@juandiegopalomino @jadengore can you read through #7 and see if this is the same issue? |
Thanks for the reports guys. The problem is indeed when using the |
In the meantime, I'm calling |
I think I found a solution on #27, although it diverges a lot from the previous implementation of this plugin and I'll require further investigation before merging. As this can take a while I suggest you use the feature/update-with-patch-option branch and let me know if the issue is fixed. |
Fix released as 1.2.0, cheers! |
@ricardogama 👏 👏 👏 👏 👏 |
Haven't gotten a chance to try this yet, but looking forward to it. Great work, @ricardogama! |
@ricardogama sorry, I lost track of the issue (need to check my notification settings) and just saw the fix. I'll get to using it immediately and thank you so much! |
@ricardogama just wanted to confirm that this does appear to work. Thanks a ton for this!!!!! |
I seem to be running into this issue again. This time, it's occurring specifically when inserting. I'm calling a function in the this.on('saving', (model, attrs, options) => {
const { pets, services } = model.attributes;
// Generate and save the report card.
return internals.generateReportCard(pets, services)
.then((reportCard) => {
model.set('reportCard', reportCard);
});
}); Anyone else having this issue? |
FYI that if I do the following, it works in both insert and update cases: return internals.generateReportCard(pets, services)
.then((reportCard) => {
if (model.isNew()) {
reportCard = JSON.stringify(reportCard);
}
model.set('reportCard', reportCard);
}); |
Hi James, I guess the trick here is with the If you're using Without I guess that the plugin behaviour diverged so much since the Anyway if you want to make your code more plain (and if it doesn't bring side effects), I think you can call the prototype bookshelf.Model.extend({
initialize() {
bookshelf.Model.prototype.initialize.apply(this, arguments);
this.on('saving', (model, attrs, options) => {
const { pets, services } = model.attributes;
// Generate and save the report card.
return internals.generateReportCard(pets, services)
.then(reportCard => {
model.set('reportCard', JSON.stringify(reportCard));
});
});
}
}); |
@ricardogama thanks for the detailed explanation and sorry to keep being a pest about this issue! I'll probably revert to specifically stringifying and parsing these fields for the time being. Again, I appreciate your hard work! |
Hi there,
This is an awesome library, and the only fault I've encountered is that it doesn't seem to stringify the JSON columns when saving as an update. I've been toying with the "updating" and "updated" event emitters, but didn't get much. Any idea on how to perfect this (or if it's even possible)?
The text was updated successfully, but these errors were encountered: