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
Upsert method #381
Comments
No but you can track it at knex/knex#54. It would be appreciated if you could share your exact use case there. This is something I'm pretty sure I've never needed even once and I believe Tim mentioned the same somewhere. That's not to say it's invalid — would just be helpful to have a hint of why people want it and how they'd use it (versus a bunch of 👍 in the thread). |
Let's say that I want to have the ability to save or update, for example, thebbilling address of a user. Instead of having two api methods for create and update, I have one that does both with an upsert. |
Can you be a little more detailed about your schema? Normally Bookshelf figures out whether a model is new based on an id. |
Oh, I never knew that. |
Possibly related: #1333 |
@bendrucker I have a good example - let's say you have a set of calculations you have to perform and you're optimizing so you save the value of the calculated into a table as a relation to the first model -- using the ID of the first model in a second table -- you can upsert using that related model's ID and the result. It's not a problem that you are blowing away the previous result because it's the correct, up to date amount and you don't care if the previous amount existed or is updated. It saves you a round trip to the database. |
bookshelf doesn't really seem to support upsert at all because the underlying knex doesn't support it either, see knex/knex#54 |
A lot of times I run into the issue of having to insert a record if it doesn't exist, and update if it doesn't. Is there an upsert method in bookshelf? If not, what would be the cleanest way to do this?
The text was updated successfully, but these errors were encountered: