-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Call model.toJSON always when sync model #4179
base: master
Are you sure you want to change the base?
Conversation
If you have to manipulate attributes before sending, why not pass already manipulated object in |
Because the object And, if For example, a model with the next
In the persistence layer, rating is stored as an integer from 0 to 5. But in our app we use rating as a number from 0 to 10. Now, we want update the rating in our model:
Currently, with this line, our model will be updated to rating 7. And the persistence layer also will receive a 7 as rating, which is wrong. This is failing also in the premise that You are suggesting to do:
Which is also wrong, because yes, your persistence layer will receive a rating of 3.5, that is the expected value. But your model will have a rating of 3.5 too, and that value is not what you want in your application. With this PR, in the same way that we have a
|
Very neat. Now it make a sense for me. Thank you for a great explanation. |
It is great PR, but i think we should add some flag, to switch for new behaviour, because it is pretty much could break someones apps
|
@ogonkov I agree with you, but I think I want this behavior to be the default in a future Backbone 2.0. How about we name the flag |
One flag for few features? @jgonggrijp |
Well, changed features. That we intend to become standard. |
When you save your model with patch option to true, toJSON isn't called. This behavior goes against the issue #1019 where it tells that:
With this PR the default behavior is the same as the current one, but it gives us the opportunity to manipulate the attributes before send them to the persistence layer, either using a POST, PATCH or PUT method.