Fix model remoting issue.
This commit is contained in:
parent
4be6ebceb7
commit
407a50f493
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue