Search code examples
model-view-controllerjavascriptjavascript-frameworkobject-relational-model

Which Javascript MVC framework best handles relational data?


I'm looking to try, for the first time, a JavaScript MVC framework like Knockout, Backbone.js, Spine, JavaScriptMVC, etc.

I've started looking at some of the documentation available for these frameworks and I'm having trouble finding examples of how they handle relational data. Most of them use a ToDo list as an example. A ToDo list is nice, but it doesn't cover relational data. Perhaps a better example would be a cookbook with a model for both recipes and ingredients:

var Recipe = function(){
   this.name = "Pizza";
   this.description = "A delicious baked, flat, disc-shaped bread topped with tomato sauce and cheese.";
}

var Ingredient = function(){
   this.name = "Tomato sauce"
}

var IngredientToRecipe = function(){
   this.recipe = null;
   this.ingredient = null;
   this.quantity;
}

The examples for models that I've seen so far do not seem to deal with the problems of relationships: foreign keys, id generation, etc. The example above is a many-to-many relationship, but I would be happy with support even for one-to-many relationships.

I really like the things provided by these frameworks:

  • changes to the models automatically update the view (i.e. DOM)
  • automatically updating the model on the server when it changes
  • clear organization of code
  • etc...

But, I'd like advice on which framework best handles relationships between models and has an example where that is done.

Thanks!


Solution

  • Sproutcore has a client side datastore which allows you to relate different model object to each other in toOne, toMany, and ManyToMany relationships. You can actually write queries against the store which automagically update when the data changes. Similarly, if you do an update and a model object changes, any views attached to that model (via a controller) will automatically update). Also, SC has a nested store functionality which allows you to abandon changes seamlessly, for the 'save or cancel' type workflows.

    http://guides.sproutcore.com/records.html