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
  1. function (parent){
  2. var options = this.__opts || {};
  3. var ds, self = this;
  4. if (!isUndefined((ds = options.dataset)) && isFunction(ds)) {
  5. ds = ds.apply(parent, [parent]);
  6. }
  7. if (!ds) {
  8. var q = {};
  9. this._setAssociationKeys(parent, q);
  10. ds = this.model.dataset.naked().filter(q);
  11. var recip = this.model._findAssociation(this);
  12. recip && (recip = recip[1]);
  13. ds.rowCb = function (item) {
  14. var model = self._toModel(item, true);
  15. recip && recip.__setValue(model, parent);
  16. //call hook to finish other model associations
  17. return model._hook("post", "load").chain(function () {
  18. return model;
  19. });
  20. };
  21. } else if (!ds.rowCb && this.model) {
  22. ds.rowCb = function (item) {
  23. var model = self._toModel(item, true);
  24. //call hook to finish other model associations
  25. return model._hook("post", "load").chain(function () {
  26. return model;
  27. });
  28. };
  29. }
  30. return this._setDatasetOptions(ds);
  31. }

_getter Function Private


Defined associations/_Association.js

Alias used to explicitly get an association on a model.

Arguments Source
  1. function (model){
  2. //if we have them return them;
  3. if (this.associationLoaded(model)) {
  4. var assoc = this.getAssociation(model);
  5. return this.isEager() ? assoc : when(assoc);
  6. } else if (model.isNew) {
  7. return null;
  8. } else {
  9. return this.fetch(model);
  10. }
  11. }

_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
  1. function (next,model){
  2. next();
  3. }

_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
  1. function (next,model){
  2. next();
  3. }

_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
  1. function (next,model){
  2. next();
  3. }

_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
  1. function (next,model){
  2. next();
  3. }

_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
  1. function (next,model){
  2. next();
  3. }

_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
  1. function (next,model){
  2. if (this.isOwner && !this.isCascading) {
  3. var q = {};
  4. this._setAssociationKeys(model, q, null);
  5. model[this.associatedDatasetName].update(q).classic(next);
  6. } else {
  7. next();
  8. }
  9. }

_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
  1. function (next,model){
  2. next();
  3. }

_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
  1. function (next,model){
  2. next();
  3. }

_setter Function Private


Defined associations/_Association.js

Alias used to explicitly set an association on a model.

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

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
  1. function (parent,name){
  2. this.name = name;
  3. var self = this;
  4. this.parent = parent;
  5. var parentProto = parent.prototype;
  6. parentProto["__defineGetter__"](name, function () {
  7. return self._getter(this);
  8. });
  9. parentProto["__defineGetter__"](this.associatedDatasetName, function () {
  10. return self._filter(this);
  11. });
  12. if (!this.readOnly && this.createSetter) {
  13. //define a setter because we arent read only
  14. parentProto["__defineSetter__"](name, function (vals) {
  15. self._setter(vals, this);
  16. });
  17. }
  18. //set up all callbacks
  19. ["pre", "post"].forEach(function (op) {
  20. ["save", "update", "remove", "load"].forEach(function (type) {
  21. parent[op](type, function (next) {
  22. return self["_" + op + type.charAt(0).toUpperCase() + type.slice(1)](next, this);
  23. });
  24. }, this);
  25. }, this);
  26. }

isEager Function Public


Defined associations/_Association.js

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

Documentation generated using coddoc.