Base class for all associations.


NOT to be instantiated directly Its just documented for reference.

Instance Properties
PropertyTypeDefault ValueDescription
_fetchMethodproperty"all"

Method to call to look up association, called after the model has been filtered

fetchTypepropertyfetch.LAZY

Fetch type

filterpropertynull

Our filter method

modelModel

the model associatied with this association.

orderBypropertynull

how to order our association

Constructor

Defined associations/_Association.js

_filter Function Private


Defined associations/_Association.js

Filters our associated dataset to load our association.

Arguments Returns Source
function (parent){
   var options = this.__opts || {};
   var ds, self = this;
   if (!isUndefined((ds = options.dataset)) && isFunction(ds)) {
       ds = ds.apply(parent, [parent]);
   }
   if (!ds) {
       var q = {};
       this._setAssociationKeys(parent, q);
       ds = this.model.dataset.naked().filter(q);
       var recip = this.model._findAssociation(this);
       recip && (recip = recip[1]);
       ds.rowCb = function (item) {
           var model = self._toModel(item, true);
           recip && recip.__setValue(model, parent);
           //call hook to finish other model associations
           return model._hook("post", "load").chain(function () {
               return model;
           });
       };
   } else if (!ds.rowCb && this.model) {
       ds.rowCb = function (item) {
           var model = self._toModel(item, true);
           //call hook to finish other model associations
           return model._hook("post", "load").chain(function () {
               return model;
           });
       };
   }
   return this._setDatasetOptions(ds);
           
}
    

_getter Function Private


Defined associations/_Association.js

Alias used to explicitly get an association on a model.

Arguments Source
function (model){
   //if we have them return them;
   if (this.associationLoaded(model)) {
       var assoc = this.getAssociation(model);
       return this.isEager() ? assoc : when(assoc);
   } else if (model.isNew) {
       return null;
   } else {
       return this.fetch(model);
   }
           
}
    

_postLoad Function Private


Defined associations/_Association.js

Middleware called after a model is loaded.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_postRemove Function Private


Defined associations/_Association.js

Middleware called aft era model is removed.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_postSave Function Private


Defined associations/_Association.js

Middleware called after a model is saved.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_postUpdate Function Private


Defined associations/_Association.js

Middleware called before a model is updated.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_preLoad Function Private


Defined associations/_Association.js

Middleware called before a model is loaded.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_preRemove Function Private


Defined associations/_Association.js

Middleware called before a model is removed.
This is called in the scope of the model

Arguments Source
function (next,model){
   if (this.isOwner && !this.isCascading) {
       var q = {};
       this._setAssociationKeys(model, q, null);
       model[this.associatedDatasetName].update(q).classic(next);
   } else {
       next();
   }
           
}
    

_preSave Function Private


Defined associations/_Association.js

Middleware called before a model is saved.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_preUpdate Function Private


Defined associations/_Association.js

Middleware called before a model is updated.
This is called in the scope of the model

Arguments Source
function (next,model){
   next();
           
}
    

_setter Function Private


Defined associations/_Association.js

Alias used to explicitly set an association on a model.

Arguments Source
function (val,model){
   model.__associations[this.name] = val;
           
}
    

inject Function Public


Defined associations/_Association.js

Method to inject functionality into a model. This method alters the model to prepare it for associations, and initializes all required middleware calls to fulfill requirements needed to loaded the associations.

Arguments Source
function (parent,name){
   this.name = name;
   var self = this;
   this.parent = parent;
   var parentProto = parent.prototype;
   parentProto["__defineGetter__"](name, function () {
       return self._getter(this);
   });
   parentProto["__defineGetter__"](this.associatedDatasetName, function () {
       return self._filter(this);
   });
   if (!this.readOnly && this.createSetter) {
       //define a setter because we arent read only
       parentProto["__defineSetter__"](name, function (vals) {
           self._setter(vals, this);
       });
   }
   //set up all callbacks
   ["pre", "post"].forEach(function (op) {
       ["save", "update", "remove", "load"].forEach(function (type) {
           parent[op](type, function (next) {
               return self["_" + op + type.charAt(0).toUpperCase() + type.slice(1)](next, this);
           });
       }, this);
   }, this);
           
}
    

isEager Function Public


Defined associations/_Association.js

Returns Source
function (){
   return this.fetchType === fetch.EAGER;
           
}
    

Documentation generated using coddoc.