1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 | var RelationIdMetadata = (function () {
|
7 |
|
8 |
|
9 |
|
10 | function RelationIdMetadata(options) {
|
11 | this.entityMetadata = options.entityMetadata;
|
12 | this.target = options.args.target;
|
13 | this.propertyName = options.args.propertyName;
|
14 | this.relationNameOrFactory = options.args.relation;
|
15 | this.alias = options.args.alias;
|
16 | this.queryBuilderFactory = options.args.queryBuilderFactory;
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 | RelationIdMetadata.prototype.setValue = function (entity) {
|
27 | var _this = this;
|
28 | var inverseEntity = this.relation.getEntityValue(entity);
|
29 | if (inverseEntity instanceof Array) {
|
30 | entity[this.propertyName] = inverseEntity.map(function (item) {
|
31 | return _this.relation.inverseEntityMetadata.getEntityIdMixedMap(item);
|
32 | }).filter(function (item) { return item !== null && item !== undefined; });
|
33 | }
|
34 | else {
|
35 | var value = this.relation.inverseEntityMetadata.getEntityIdMixedMap(inverseEntity);
|
36 | if (value !== undefined)
|
37 | entity[this.propertyName] = value;
|
38 | }
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 | RelationIdMetadata.prototype.build = function () {
|
48 | var propertyPath = this.relationNameOrFactory instanceof Function ? this.relationNameOrFactory(this.entityMetadata.propertiesMap) : this.relationNameOrFactory;
|
49 | var relation = this.entityMetadata.findRelationWithPropertyPath(propertyPath);
|
50 | if (!relation)
|
51 | throw new Error("Cannot find relation " + propertyPath + ". Wrong relation specified for @RelationId decorator.");
|
52 | this.relation = relation;
|
53 | };
|
54 | return RelationIdMetadata;
|
55 | }());
|
56 | exports.RelationIdMetadata = RelationIdMetadata;
|
57 |
|
58 |
|