lib/factories/model.factory.js
function getModel(service, mixins) {

        // model constructor takes in data and saves it along with the model mixins
        var Model = function (data) {
            _.extend(this, data, mixins);
        };

        if (service.save) {
            Model.prototype.save = function () {
                if (this._id) {
                    return service.save({ where: { _id: this._id }, data: this });
                }
                else {
                    return service.save({ data: this });
                }
            };
        }
        else if (service.create && service.update) {
            Model.prototype.save = function () {
                if (this._id) {
                    return service.update({ where: { _id: this._id }, data: this });
                }
                else {
                    return service.create({ data: this });
                }
            };
        }

        if (service.remove) {
            Model.prototype.remove = function () {
                return service.remove({ where: { _id: this._id } });
            };
        }

        // the service methods are added as static references on the model
        _.each(service, function (method, methodName) {
            Model[methodName] = function () {
                return service[methodName].apply(service, arguments);
            };
        });

        return Model;
    }
function getModel(service, mixins) {

        // model constructor takes in data and saves it along with the model mixins
        var Model = function (data) {
            _.extend(this, data, mixins);
        };

        if (service.save) {
            Model.prototype.save = function () {
                if (this._id) {
                    return service.save({ where: { _id: this._id }, data: this });
                }
                else {
                    return service.save({ data: this });
                }
            };
        }
        else if (service.create && service.update) {
            Model.prototype.save = function () {
                if (this._id) {
                    return service.update({ where: { _id: this._id }, data: this });
                }
                else {
                    return service.create({ data: this });
                }
            };
        }

        if (service.remove) {
            Model.prototype.remove = function () {
                return service.remove({ where: { _id: this._id } });
            };
        }

        // the service methods are added as static references on the model
        _.each(service, function (method, methodName) {
            Model[methodName] = function () {
                return service[methodName].apply(service, arguments);
            };
        });

        return Model;
    }
function getModel ( service , mixins ) { // model constructor takes in data and saves it along with the model mixins var Model = function ( data ) { _ . extend ( this , data , mixins ) ; } ; if ( service . save ) { Model . prototype . save = function ( ) { if ( this . _id ) { return service . save ( { where : { _id : this . _id } , data : this } ) ; } else { return service . save ( { data : this } ) ; } } ; } else if ( service . create && service . update ) { Model . prototype . save = function ( ) { if ( this . _id ) { return service . update ( { where : { _id : this . _id } , data : this } ) ; } else { return service . create ( { data : this } ) ; } } ; } if ( service . remove ) { Model . prototype . remove = function ( ) { return service . remove ( { where : { _id : this . _id } } ) ; } ; } // the service methods are added as static references on the model _ . each ( service , function ( method , methodName ) { Model [ methodName ] = function ( ) { return service [ methodName ] . apply ( service , arguments ) ; } ; } ) ; return Model ; }
Get a model based on a service and resource
@param service
@param mixins
@returns {Model}
Get a model based on a service and resource