1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var QueryBuilderUtils_1 = require("./QueryBuilderUtils");
|
5 | var ObjectUtils_1 = require("../util/ObjectUtils");
|
6 |
|
7 |
|
8 |
|
9 | var JoinAttribute = (function () {
|
10 |
|
11 |
|
12 |
|
13 | function JoinAttribute(connection, queryExpressionMap, joinAttribute) {
|
14 | this.connection = connection;
|
15 | this.queryExpressionMap = queryExpressionMap;
|
16 | this.isSelectedEvalueated = false;
|
17 | this.relationEvalueated = false;
|
18 | ObjectUtils_1.ObjectUtils.assign(this, joinAttribute || {});
|
19 | }
|
20 | Object.defineProperty(JoinAttribute.prototype, "isMany", {
|
21 |
|
22 |
|
23 |
|
24 | get: function () {
|
25 | if (this.isMappingMany !== undefined)
|
26 | return this.isMappingMany;
|
27 | if (this.relation)
|
28 | return this.relation.isManyToMany || this.relation.isOneToMany;
|
29 | return false;
|
30 | },
|
31 | enumerable: true,
|
32 | configurable: true
|
33 | });
|
34 | Object.defineProperty(JoinAttribute.prototype, "isSelected", {
|
35 | |
36 |
|
37 |
|
38 | get: function () {
|
39 | var _this = this;
|
40 | if (!this.isSelectedEvalueated) {
|
41 | var getValue = function () {
|
42 | var e_1, _a;
|
43 | var _loop_1 = function (select) {
|
44 | if (select.selection === _this.alias.name)
|
45 | return { value: true };
|
46 | if (_this.metadata && !!_this.metadata.columns.find(function (column) { return select.selection === _this.alias.name + "." + column.propertyPath; }))
|
47 | return { value: true };
|
48 | };
|
49 | try {
|
50 | for (var _b = tslib_1.__values(_this.queryExpressionMap.selects), _c = _b.next(); !_c.done; _c = _b.next()) {
|
51 | var select = _c.value;
|
52 | var state_1 = _loop_1(select);
|
53 | if (typeof state_1 === "object")
|
54 | return state_1.value;
|
55 | }
|
56 | }
|
57 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
58 | finally {
|
59 | try {
|
60 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
61 | }
|
62 | finally { if (e_1) throw e_1.error; }
|
63 | }
|
64 | return false;
|
65 | };
|
66 | this.isSelectedCache = getValue();
|
67 | this.isSelectedEvalueated = true;
|
68 | }
|
69 | return this.isSelectedCache;
|
70 | },
|
71 | enumerable: true,
|
72 | configurable: true
|
73 | });
|
74 | Object.defineProperty(JoinAttribute.prototype, "tablePath", {
|
75 | |
76 |
|
77 |
|
78 | get: function () {
|
79 | return this.metadata ? this.metadata.tablePath : this.entityOrProperty;
|
80 | },
|
81 | enumerable: true,
|
82 | configurable: true
|
83 | });
|
84 | Object.defineProperty(JoinAttribute.prototype, "parentAlias", {
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | get: function () {
|
92 | if (!QueryBuilderUtils_1.QueryBuilderUtils.isAliasProperty(this.entityOrProperty))
|
93 | return undefined;
|
94 | return this.entityOrProperty.substr(0, this.entityOrProperty.indexOf("."));
|
95 | },
|
96 | enumerable: true,
|
97 | configurable: true
|
98 | });
|
99 | Object.defineProperty(JoinAttribute.prototype, "relationPropertyPath", {
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | get: function () {
|
108 | if (!QueryBuilderUtils_1.QueryBuilderUtils.isAliasProperty(this.entityOrProperty))
|
109 | return undefined;
|
110 | return this.entityOrProperty.substr(this.entityOrProperty.indexOf(".") + 1);
|
111 | },
|
112 | enumerable: true,
|
113 | configurable: true
|
114 | });
|
115 | Object.defineProperty(JoinAttribute.prototype, "relation", {
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | get: function () {
|
123 | var _this = this;
|
124 | if (!this.relationEvalueated) {
|
125 | var getValue = function () {
|
126 | if (!QueryBuilderUtils_1.QueryBuilderUtils.isAliasProperty(_this.entityOrProperty))
|
127 | return undefined;
|
128 | var relationOwnerSelection = _this.queryExpressionMap.findAliasByName(_this.parentAlias);
|
129 | var relation = relationOwnerSelection.metadata.findRelationWithPropertyPath(_this.relationPropertyPath);
|
130 | if (relation) {
|
131 | return relation;
|
132 | }
|
133 | if (relationOwnerSelection.metadata.parentEntityMetadata) {
|
134 | relation = relationOwnerSelection.metadata.parentEntityMetadata.findRelationWithPropertyPath(_this.relationPropertyPath);
|
135 | if (relation) {
|
136 | return relation;
|
137 | }
|
138 | }
|
139 | throw new Error("Relation with property path " + _this.relationPropertyPath + " in entity was not found.");
|
140 | };
|
141 | this.relationCache = getValue.bind(this)();
|
142 | this.relationEvalueated = true;
|
143 | }
|
144 | return this.relationCache;
|
145 | },
|
146 | enumerable: true,
|
147 | configurable: true
|
148 | });
|
149 | Object.defineProperty(JoinAttribute.prototype, "metadata", {
|
150 | |
151 |
|
152 |
|
153 |
|
154 | get: function () {
|
155 |
|
156 | if (this.relation)
|
157 | return this.relation.inverseEntityMetadata;
|
158 |
|
159 | if (this.connection.hasMetadata(this.entityOrProperty))
|
160 | return this.connection.getMetadata(this.entityOrProperty);
|
161 | return undefined;
|
162 | |
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | },
|
174 | enumerable: true,
|
175 | configurable: true
|
176 | });
|
177 | Object.defineProperty(JoinAttribute.prototype, "junctionAlias", {
|
178 | |
179 |
|
180 |
|
181 | get: function () {
|
182 | if (!this.relation)
|
183 | throw new Error("Cannot get junction table for join without relation.");
|
184 | return this.relation.isOwning ? this.parentAlias + "_" + this.alias.name : this.alias.name + "_" + this.parentAlias;
|
185 | },
|
186 | enumerable: true,
|
187 | configurable: true
|
188 | });
|
189 | Object.defineProperty(JoinAttribute.prototype, "mapToPropertyParentAlias", {
|
190 | get: function () {
|
191 | if (!this.mapToProperty)
|
192 | return undefined;
|
193 | return this.mapToProperty.split(".")[0];
|
194 | },
|
195 | enumerable: true,
|
196 | configurable: true
|
197 | });
|
198 | Object.defineProperty(JoinAttribute.prototype, "mapToPropertyPropertyName", {
|
199 | get: function () {
|
200 | if (!this.mapToProperty)
|
201 | return undefined;
|
202 | return this.mapToProperty.split(".")[1];
|
203 | },
|
204 | enumerable: true,
|
205 | configurable: true
|
206 | });
|
207 | return JoinAttribute;
|
208 | }());
|
209 | exports.JoinAttribute = JoinAttribute;
|
210 |
|
211 |
|