Scalable approach to implement many

Is there a tested and scalable approach for many-to-many relations based on Backbone-Associations? I have been looking at Backbone-Relational and Backbone-JJRelational as a replacement, but would like to keep Backbone-Associations for other reasons and constraints.

I have a two models (Project and Location) with respective collections, and each model have a many relation to the other. One project can have more than one location, and one location can host multiple projects.

// Non-relevant statements have been left out 

var Project = Backbone.AssociatedModel.extend({
    relations: [{
        type: Backbone.Many,
        key: 'locations',
        collectionType: Locations
    }],
    defaults: 


});

var Projects = Backbone.Collection.extend({
    model: Project
});

var Location = Backbone.AssociatedModel.extend({
    relations: [{
        type: Backbone.Many,
        key: 'projects',
        collectionType: Projects
    }]
});

var Locations = Backbone.Collection.extend({
    model: Location
});

Would prefer solutions put in production, if not just pointers on how to solve the problem in the most scalable and robust way. (The REST API is implemented on NodeJS/Express and MongoDB if that has an impact)

Cheeers


For what it's worth I decided to implement the relations with a flat nested structure and keep arrays with references in the models with relations instead. I believe Backbone-Associations and Backbone-Relational are great for on-to-one and one-to-many relations, but for more complex nested structures it seems more efficient to implement a "home-cooked" relational structure.

The flexibility to implement reusable structures that maps to the specific constraints of my entity model and more control of the event handling made me come to this conclusion. I have roughly 25 models and 30 collections, and there are quite a few many-to-many relations in this.

(It needs to be said that I am fairly new to JavaScript and Backbone, so this might have an impact on the decision)

链接地址: http://www.djcxy.com/p/65532.html

上一篇: 在Backbone Marionette中为相关模型创建新实体

下一篇: 实施许多可扩展的方法