Base class for all associations.
NOT to be instantiated directly Its just documented for reference.
Instance PropertiesProperty | Type | Default Value | Description |
_fetchMethod | property | "all" | Method to call to look up association, called after the model has been filtered |
fetchType | property | fetch.LAZY | Fetch type |
filter | property | null | Our filter method |
model | Model | the model associatied with this association. | |
orderBy | property | null | how to order our association |
Filters our associated dataset to load our association.
ArgumentsDataset
the dataset with all filters applied.
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); }
Alias used to explicitly get an association on a model.
Arguments_Association
: reference to the Association that is being called.
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); } }
Middleware called after a model is loaded. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Middleware called aft era model is removed. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Middleware called after a model is saved. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Middleware called before a model is updated. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Middleware called before a model is loaded. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Middleware called before a model is removed. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being acted up.
function (next,model){ if (this.isOwner && !this.isCascading) { var q = {}; this._setAssociationKeys(model, q, null); model[this.associatedDatasetName].update(q).classic(next); } else { next(); } }
Middleware called before a model is saved. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Middleware called before a model is updated. This is called in the scope of the model
Argumentsfunction to pass control up the middleware stack.
_Association
: reference to the Association that is being called.
function (next,model){ next(); }
Alias used to explicitly set an association on a model.
Argumentsthe value to set the association to
_Association
: reference to the Association that is being called.
function (val,model){ model.__associations[this.name] = val; }
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.
Argumentsthe model that is having an associtaion set on it.
the name of the association.
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); }
Boolean
true if the association is eager.
function (){ return this.fetchType === fetch.EAGER; }