From cd4dba79dc63f354c98bd16345c7b5ef40d8af04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 24 Jul 2014 19:52:55 +0200 Subject: [PATCH] relation: add `scope._target` for `hasOne` Add `_target` property to the scope method created by `hasOne` relationship. The `_target` property is used by loopback-sdk-angular. --- lib/relation-definition.js | 1 + test/relations.test.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 2aaa70b9..9279fc7e 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -1055,6 +1055,7 @@ RelationDefinition.hasOne = function (modelFrom, modelTo, params) { var relationMethod = relation.related.bind(relation) relationMethod.create = relation.create.bind(relation); relationMethod.build = relation.build.bind(relation); + relationMethod._targetClass = relationDef.modelTo.modelName; return relationMethod; } }); diff --git a/test/relations.test.js b/test/relations.test.js index 5f52b4c0..f091486d 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -658,6 +658,9 @@ describe('relations', function () { }); }); + it('should set targetClass on scope property', function() { + should.equal(Supplier.prototype.account._targetClass, 'Account'); + }); }); describe('hasAndBelongsToMany', function () {