-
Notifications
You must be signed in to change notification settings - Fork 299
Fixes recursive loop if model attributes contain nested models #97
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
Fixes recursive loop if model attributes contain nested models #97
Conversation
I.e. nested models created from the backbone-relational plugin
Thanks for the pull. We have a discussion going on in #93 regarding this. Feel free to join it:-) |
Better way to fix that is if (obj instanceof Backbone.Model || obj instanceof Backbone.Collection) {
obj = obj.toJSON();
} Why? I have an model in that model there is sub-model as Array that represents a GeoPoint like this // Specify validator
_.extend(Backbone.Validation.validators, {
point: function(value, attr, customValue, model) {
var isValid = _.isArray(value) &&
value.length === 2 &&
typeof value[0] === 'number' &&
typeof value[1] === 'number';
if (!isValid) {
return 'It should be geo point';
}
}
}); |
There is also can be a case when someone is required to validate sub-models... so |
FWIW, toJSON does not transform sub-models into plain JSON automatically. |
@thedersen There has been no update of this plugin for 5 months. It would be awesome if you could make a release at least with the current "important pull request" (this one, #125) + Backbone 1.0 compatibility. Is it possible ? |
I dunno if we'll hear from @thedersen anytime soon, so I went ahead and found this plugin which does all the validation I personally need, and the maintainer has been very responsive. |
@wulftone Thanks for sharing. Is it hard to switch ? |
I didn't think it was hard, but then again, I didn't have a lot of models to validate. The two plugins work largely the same, though the mechanism for triggering events is a little different. The source code is really easy to read, and the plugin manages to do much of the same as this one, but is about 5/8ths as large (5.2kb min, 8.2kb min). Being that it's smaller, it's also pretty easy to grok and extend. |
I'm sorry I have not had the time to follow up this project as much as I would like to. Hopefully I will get to spend some time fixing these issues in the next couple of weeks. |
That's good news thanks !!! |
I have now merged this. Hopefully this fixes some of the issues you are having. |
I.e. nested models created from the backbone-relational plugin