Fix model remoting issue.

This commit is contained in:
Ritchie Martori 2013-07-16 10:25:02 -07:00
parent 4be6ebceb7
commit 407a50f493
2 changed files with 20 additions and 24 deletions

View File

@ -13,26 +13,6 @@ var Model = module.exports = modeler.define('model');
Model.shared = true; Model.shared = true;
/*!
* For **remoting**. Construct objects when calling instance methods remotely.
*/
// after remote hook
Model.afterRemote = function (name, fn) {
var self = this;
if(this.app) {
var remotes = this.app.remotes();
remotes.after(self.pluralModelName + '.' + name, function (ctx, next) {
fn(ctx, ctx.result, next);
});
} else {
var args = arguments;
this.once('attached', function () {
self.afterRemote.apply(self, args);
});
}
}
/*! /*!
* Called when a model is extended. * Called when a model is extended.
*/ */
@ -62,11 +42,11 @@ Model.setup = function () {
} }
if(id && data) { if(id && data) {
var model = new ModelCtor(data); var model = new ModelCtor(data, {remote: true});
model.id = id; model.id = id;
fn(null, model); fn(null, model);
} else if(data) { } else if(data) {
fn(null, new ModelCtor(data)); fn(null, new ModelCtor(data, {remote: true}));
} else if(id) { } else if(id) {
ModelCtor.find(id, function (err, model) { ModelCtor.find(id, function (err, model) {
if(err) { if(err) {
@ -101,6 +81,22 @@ Model.setup = function () {
} }
} }
// after remote hook
ModelCtor.afterRemote = function (name, fn) {
var self = this;
if(this.app) {
var remotes = this.app.remotes();
remotes.after(self.pluralModelName + '.' + name, function (ctx, next) {
fn(ctx, ctx.result, next);
});
} else {
var args = arguments;
this.once('attached', function () {
self.afterRemote.apply(self, args);
});
}
}
ModelCtor.sharedCtor.accepts = [ ModelCtor.sharedCtor.accepts = [
{arg: 'data', type: 'object', http: {source: 'body'}}, {arg: 'data', type: 'object', http: {source: 'body'}},
{arg: 'id', type: 'any', http: {source: 'url'}} {arg: 'id', type: 'any', http: {source: 'url'}}

View File

@ -18,7 +18,7 @@ var Model = require('../asteroid').Model
var properties = { var properties = {
realm: {type: String, }, realm: {type: String, },
username: {type: String, required: true}, username: {type: String, required: true},
password: {type: String, transient: true}, // Transient property password: {type: String, hideRemotely: true}, // Transient property
email: String, email: String,
emailVerified: Boolean, emailVerified: Boolean,
verificationToken: String, verificationToken: String,