2012-12-20 80 views

回答

0

晚了十年,但Spine.js沒有has_many關係。

引述source code,它只有屬於關聯,hasOne和的hasMany:

Spine.Model.extend({ 
    hasMany: function(name, model, fkey) { 
     if (fkey == null) { 
     fkey = (underscore(this.className)) + "_id"; 
     } 
     return this.prototype[name] = function(value) { 
     return association(name, model, this, fkey, Collection).refresh(value); 
     }; 
    }, 
    belongsTo: function(name, model, fkey) { 
     if (fkey == null) { 
     fkey = (underscore(singularize(name))) + "_id"; 
     } 
     this.prototype[name] = function(value) { 
     return association(name, model, this, fkey, Instance).update(value).find(); 
     }; 
     return this.attributes.push(fkey); 
    }, 
    hasOne: function(name, model, fkey) { 
     if (fkey == null) { 
     fkey = (underscore(this.className)) + "_id"; 
     } 
     return this.prototype[name] = function(value) { 
     return association(name, model, this, fkey, Singleton).update(value).find(); 
     }; 
    } 
    });