From 73f4a1bbe6786b674f57fb3599b78f1f3ad22631 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Sat, 21 Mar 2015 16:14:47 +0100 Subject: [PATCH] Enable more CRUD remoting methods for embedsOne --- lib/relation-definition.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 232f232a..567a0636 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -1816,11 +1816,25 @@ RelationDefinition.embedsOne = function (modelFrom, modelTo, params) { // FIXME: [rfeng] Wrap the property into a function for remoting // so that it can be accessed as /api/// // For example, /api/orders/1/customer - var fn = function() { + modelFrom.prototype['__get__' + relationName] = function() { var f = this[relationName]; f.apply(this, arguments); }; - modelFrom.prototype['__get__' + relationName] = fn; + + modelFrom.prototype['__create__' + relationName] = function() { + var f = this[relationName].create; + f.apply(this, arguments); + }; + + modelFrom.prototype['__update__' + relationName] = function() { + var f = this[relationName].update; + f.apply(this, arguments); + }; + + modelFrom.prototype['__destroy__' + relationName] = function() { + var f = this[relationName].destroy; + f.apply(this, arguments); + }; return definition; };