Model Validation
See original GitHub issueYo, I am coming over from Sequelize ORM and for the most part migration has been pretty easy. However, while I was working with the Bookshelf ORM I noticed a few things about validation that have me confused about how it should be implemented.
First there is this comment in the source for the save method:
// Sets and saves the hash of model attributes, triggering
// a "creating" or "updating" event on the model, as well as a "saving" event,
// to bind listeners for any necessary validation, logging, etc.
// If an error is thrown during these events, the model will not be saved.
Then there is this comment above the _validate method.
// Validation can be complicated, and is better handled
// on its own and not mixed in with database logic.
So I can’t tell if the plan is just to completely omit model validation from this ORM or not? Sequelize uses node-validator https://github.com/chriso/node-validator and I began to attempt implementing the missing validation methods that were omitted/stripped from the backbone inheritance, but stopped because I don’t know if it’s something Bookshelf is even interested in.
Can anyone tell me the plan for validation and Bookshelf or advise the best way to implement validation against my model if there is no intention to support it?
Thanks!
Issue Analytics
- State:
- Created 10 years ago
- Comments:15 (8 by maintainers)
Top GitHub Comments
I believe this is exactly what I needed. Can you verify if the implementation is ok? I want to share it incase others are interested in this. Your example above demonstrates use for more complex cases, I think - which is pretty cool.
Model:
Usage:
Not at all @thetutlage. Please open a new issue though if you’re having trouble.