Merge pull request #525 from fabien/fix/embeds-one-remoting

Enable more CRUD remoting methods for embedsOne
This commit is contained in:
Raymond Feng 2015-03-22 07:56:13 -07:00
commit 99396387ee
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
// so that it can be accessed as /api/<model>/<id>/<embedsOneRelationName>
// 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;
};