-
Notifications
You must be signed in to change notification settings - Fork 127
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
[discussion] On "enforce: missing" timing #29
Comments
I didn't think of your case when adding Instead of having a boolean, we can have multiple option for enforcing
How does it sound to you @nikaspran? |
I'd have to agree that flexibility would probably be the best solution. I can see why the option to check the model for consistency on creation might be useful too. 👍 |
It's now an option, and by default it validates the document before saving it. |
As I am not sure what the desired behavior should be, I wanted to start a discussion on
enforce: missing
and it's timing.At the moment, this option is enforced in
Model.checkType()
, which is called when creating a new instance of the Model. Meanwhile in traditional RDBMS/ORMs the constraint checks are usually performed on save to DB.I realize this is an entirely different paradigm, and the missing field enforcement doesn't actually happen in RethinkDB unlike traditional constraints (as in, it's a concept of Thinky), but I am not sure if the current way is preferable.
IMO, there are a few issues with the way Thinky enforces missing fields:
enforce: missing
field to an existing schema), any queries I do on that table that return the document will explode. I'd say this is the main problem with the current approach.Here is what I would suggest:
Model.checkType()
duringModel.save()
(before passing on to RethinkDB driver) and only then. If it fails, return an error to the callback. This would let us handle the enforcement error in the same place as any other RethinkDB errors, slightly reducing code. It would also mirror the way a lot of traditional DBs/ORMs do it, reducing adoption confusion :)Any other ideas would be welcome. Does this sound reasonable at all?
The text was updated successfully, but these errors were encountered: