js/data/Model.js
function (options, callback) {

            if (arguments.length === 1 && options instanceof Function) {
                callback = options;
                options = null;
            }

            options = options || {};

            var self = this;

            if (this._fetch.state === FETCHSTATE.LOADING) {
                // currently fetching -> register callback
                this._fetch.callbacks.push(function (err, model) {
                    modelFetchedComplete(err, model, options, callback);
                });
            } else if (this._fetch.state == FETCHSTATE.LOADED && !options.noCache) {
                // completed loaded -> execute
                modelFetchedComplete(null, this, options, callback);
            } else {
                // set state and start loading
                self._fetch.state = FETCHSTATE.LOADING;

                this.$context.$dataSource.loadModel(this, options, function (err, model) {
                    self._fetch.state = err ? FETCHSTATE.ERROR : FETCHSTATE.LOADED;

                    // execute callbacks
                    modelFetchedComplete.call(self, err, model, options, callback);

                    _.each(self._fetch.callbacks, function (cb) {
                        cb.call(self, err, model);
                    });

                });
            }
        }
function (options, callback) {

            if (arguments.length === 1 && options instanceof Function) {
                callback = options;
                options = null;
            }

            options = options || {};

            var self = this;

            if (this._fetch.state === FETCHSTATE.LOADING) {
                // currently fetching -> register callback
                this._fetch.callbacks.push(function (err, model) {
                    modelFetchedComplete(err, model, options, callback);
                });
            } else if (this._fetch.state == FETCHSTATE.LOADED && !options.noCache) {
                // completed loaded -> execute
                modelFetchedComplete(null, this, options, callback);
            } else {
                // set state and start loading
                self._fetch.state = FETCHSTATE.LOADING;

                this.$context.$dataSource.loadModel(this, options, function (err, model) {
                    self._fetch.state = err ? FETCHSTATE.ERROR : FETCHSTATE.LOADED;

                    // execute callbacks
                    modelFetchedComplete.call(self, err, model, options, callback);

                    _.each(self._fetch.callbacks, function (cb) {
                        cb.call(self, err, model);
                    });

                });
            }
        }
function ( options , callback ) { if ( arguments . length === 1 && options instanceof Function ) { callback = options ; options = null ; } options = options || { } ; var self = this ; if ( this . _fetch . state === FETCHSTATE . LOADING ) { // currently fetching -> register callback this . _fetch . callbacks . push ( function ( err , model ) { modelFetchedComplete ( err , model , options , callback ) ; } ) ; } else if ( this . _fetch . state == FETCHSTATE . LOADED && ! options . noCache ) { // completed loaded -> execute modelFetchedComplete ( null , this , options , callback ) ; } else { // set state and start loading self . _fetch . state = FETCHSTATE . LOADING ; this . $context . $dataSource . loadModel ( this , options , function ( err , model ) { self . _fetch . state = err ? FETCHSTATE . ERROR : FETCHSTATE . LOADED ; // execute callbacks modelFetchedComplete . call ( self , err , model , options , callback ) ; _ . each ( self . _fetch . callbacks , function ( cb ) { cb . call ( self , err , model ) ; } ) ; } ) ; } }
Fetches the model over the given DataSource. The id of the model must be set.

@param {Object} options
@param {Array} options.fetchSubModels - array of submodels to fetch
@param {Function} callback - function(err, model, options)
Fetches the model over the given DataSource . The id of the model must be set .