backbone-orm icon indicating copy to clipboard operation
backbone-orm copied to clipboard

Extend Backbone.Model/Collection classes with relation functionality

Open fbuchinger opened this issue 14 years ago • 1 comments

Your project sounds interesting and I'm eager to give it a try. One question though: why don't you provide your "orm" functionality by extending Backbone's Model/Collection classes instead of "mixing" in these functions via initialize? I'm thinking of something like:

Pokepic.Model = Backbone.Model.extend({
    hasMany: {},
    embedsMany:{},
    _setupRelations: (){
         //all inner relations are setup here
     }
});

The user would then simply use your Pokepic.Model / Pokepic.Collection to specify his tasks.

fbuchinger avatar Mar 21 '11 08:03 fbuchinger

That would be a possibility. At first I didn't want to change backbone directly for this project.

The problem with your solution is when the overridden initialize do not call the super initializer (as it is not done by the language). Also initialize is called by the backbone.model constructor which would require changes to backbone directly.

juggy avatar Mar 21 '11 13:03 juggy