From 407a50f493c8a215efd66bf8ab4559839a4d2ad9 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 16 Jul 2013 10:25:02 -0700 Subject: [PATCH] Fix model remoting issue. --- lib/models/model.js | 42 +++++++++++++++++++----------------------- lib/models/user.js | 2 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/models/model.js b/lib/models/model.js index f989940a..cee50fa3 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -13,26 +13,6 @@ var Model = module.exports = modeler.define('model'); 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. */ @@ -62,11 +42,11 @@ Model.setup = function () { } if(id && data) { - var model = new ModelCtor(data); + var model = new ModelCtor(data, {remote: true}); model.id = id; fn(null, model); } else if(data) { - fn(null, new ModelCtor(data)); + fn(null, new ModelCtor(data, {remote: true})); } else if(id) { ModelCtor.find(id, function (err, model) { 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 = [ {arg: 'data', type: 'object', http: {source: 'body'}}, {arg: 'id', type: 'any', http: {source: 'url'}} @@ -110,7 +106,7 @@ Model.setup = function () { {path: '/'}, {path: '/:id'} ]; - + return ModelCtor; } diff --git a/lib/models/user.js b/lib/models/user.js index 2410d367..f99f127f 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -18,7 +18,7 @@ var Model = require('../asteroid').Model var properties = { realm: {type: String, }, username: {type: String, required: true}, - password: {type: String, transient: true}, // Transient property + password: {type: String, hideRemotely: true}, // Transient property email: String, emailVerified: Boolean, verificationToken: String,