Enable more CRUD remoting methods for embedsOne

This commit is contained in:
Fabien Franzen 2015-03-21 16:14:47 +01:00
parent 5d0b745f31
commit 73f4a1bbe6
1 changed files with 16 additions and 2 deletions

View File

@ -1816,11 +1816,25 @@ RelationDefinition.embedsOne = function (modelFrom, modelTo, params) {
// FIXME: [rfeng] Wrap the property into a function for remoting // FIXME: [rfeng] Wrap the property into a function for remoting
// so that it can be accessed as /api/<model>/<id>/<embedsOneRelationName> // so that it can be accessed as /api/<model>/<id>/<embedsOneRelationName>
// For example, /api/orders/1/customer // For example, /api/orders/1/customer
var fn = function() { modelFrom.prototype['__get__' + relationName] = function() {
var f = this[relationName]; var f = this[relationName];
f.apply(this, arguments); 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; return definition;
}; };