@tachybase/database 1.3.54-alpha.3 → 1.3.54-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -64,6 +64,7 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
|
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
checkAssociationKeys() {
|
|
67
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
67
68
|
let { foreignKey, targetKey } = this.options;
|
|
68
69
|
if (!targetKey) {
|
|
69
70
|
targetKey = this.TargetModel.primaryKeyAttribute;
|
|
@@ -71,9 +72,25 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
|
|
|
71
72
|
if (!foreignKey) {
|
|
72
73
|
foreignKey = import_lodash.default.camelCase(`${this.name}_${targetKey}`);
|
|
73
74
|
}
|
|
74
|
-
const targetKeyAttribute = this.TargetModel.rawAttributes[targetKey];
|
|
75
|
-
const foreignKeyAttribute = this.collection.model.rawAttributes[foreignKey];
|
|
75
|
+
const targetKeyAttribute = (_a = this.TargetModel.rawAttributes) == null ? void 0 : _a[targetKey];
|
|
76
|
+
const foreignKeyAttribute = (_b = this.collection.model.rawAttributes) == null ? void 0 : _b[foreignKey];
|
|
77
|
+
(_g = this.context.database.logger) == null ? void 0 : _g.error(
|
|
78
|
+
`[BelongsToField.checkAssociationKeys] Field: ${this.name}, Collection: ${this.collection.name}, Target: ${this.target}, targetKey: ${targetKey}, foreignKey: ${foreignKey}`,
|
|
79
|
+
{
|
|
80
|
+
submodule: "BelongsToField",
|
|
81
|
+
method: "checkAssociationKeys",
|
|
82
|
+
targetKey,
|
|
83
|
+
foreignKey,
|
|
84
|
+
targetKeyAttribute: targetKeyAttribute ? { type: (_d = (_c = targetKeyAttribute.type) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name, field: targetKeyAttribute.field } : null,
|
|
85
|
+
foreignKeyAttribute: foreignKeyAttribute ? { type: (_f = (_e = foreignKeyAttribute.type) == null ? void 0 : _e.constructor) == null ? void 0 : _f.name, field: foreignKeyAttribute.field } : null,
|
|
86
|
+
targetModelAttributes: Object.keys(this.TargetModel.rawAttributes || {}),
|
|
87
|
+
collectionModelAttributes: Object.keys(this.collection.model.rawAttributes || {})
|
|
88
|
+
}
|
|
89
|
+
);
|
|
76
90
|
if (!foreignKeyAttribute || !targetKeyAttribute) {
|
|
91
|
+
(_h = this.context.database.logger) == null ? void 0 : _h.warn(
|
|
92
|
+
`[BelongsToField.checkAssociationKeys] Skipping check - foreignKeyAttribute: ${!!foreignKeyAttribute}, targetKeyAttribute: ${!!targetKeyAttribute}`
|
|
93
|
+
);
|
|
77
94
|
return;
|
|
78
95
|
}
|
|
79
96
|
const foreignKeyType = foreignKeyAttribute.type.constructor.toString();
|
|
@@ -85,9 +102,27 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
|
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
bind() {
|
|
105
|
+
var _a, _b, _c;
|
|
88
106
|
const { database, collection } = this.context;
|
|
89
107
|
const Target = this.TargetModel;
|
|
108
|
+
(_a = database.logger) == null ? void 0 : _a.error(
|
|
109
|
+
`[BelongsToField.bind] Field: ${this.name}, Collection: ${collection.name}, Target: ${this.target}, TargetModel: ${(Target == null ? void 0 : Target.name) || "undefined"}`,
|
|
110
|
+
{
|
|
111
|
+
submodule: "BelongsToField",
|
|
112
|
+
method: "bind",
|
|
113
|
+
fieldName: this.name,
|
|
114
|
+
collectionName: collection.name,
|
|
115
|
+
target: this.target,
|
|
116
|
+
targetModelName: Target == null ? void 0 : Target.name,
|
|
117
|
+
targetModelPrimaryKey: Target == null ? void 0 : Target.primaryKeyAttribute,
|
|
118
|
+
targetModelAttributes: Target ? Object.keys(Target.rawAttributes || {}) : [],
|
|
119
|
+
options: this.options
|
|
120
|
+
}
|
|
121
|
+
);
|
|
90
122
|
if (!Target) {
|
|
123
|
+
(_b = database.logger) == null ? void 0 : _b.warn(
|
|
124
|
+
`[BelongsToField.bind] Target model not found, adding to pending: ${this.name} in ${collection.name} -> ${this.target}`
|
|
125
|
+
);
|
|
91
126
|
database.addPendingField(this);
|
|
92
127
|
return false;
|
|
93
128
|
}
|
|
@@ -95,11 +130,20 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
|
|
|
95
130
|
if (collection.model.associations[this.name]) {
|
|
96
131
|
delete collection.model.associations[this.name];
|
|
97
132
|
}
|
|
98
|
-
const
|
|
133
|
+
const belongsToOptions = {
|
|
99
134
|
as: this.name,
|
|
100
135
|
constraints: false,
|
|
101
136
|
...(0, import_lodash.omit)(this.options, ["name", "type", "target", "onDelete"])
|
|
137
|
+
};
|
|
138
|
+
(_c = database.logger) == null ? void 0 : _c.error(`[BelongsToField.bind] Calling belongsTo with options:`, {
|
|
139
|
+
submodule: "BelongsToField",
|
|
140
|
+
method: "bind",
|
|
141
|
+
fieldName: this.name,
|
|
142
|
+
collectionName: collection.name,
|
|
143
|
+
targetModelName: Target.name,
|
|
144
|
+
belongsToOptions
|
|
102
145
|
});
|
|
146
|
+
const association = collection.model.belongsTo(Target, belongsToOptions);
|
|
103
147
|
database.removePendingField(this);
|
|
104
148
|
if (!this.options.foreignKey) {
|
|
105
149
|
this.options.foreignKey = association.foreignKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/database",
|
|
3
|
-
"version": "1.3.54-alpha.
|
|
3
|
+
"version": "1.3.54-alpha.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"semver": "7.7.2",
|
|
23
23
|
"sequelize": "^6.37.7",
|
|
24
24
|
"umzug": "^3.8.2",
|
|
25
|
-
"@tachybase/
|
|
26
|
-
"@tachybase/
|
|
27
|
-
"@tachybase/utils": "1.3.54-alpha.
|
|
25
|
+
"@tachybase/globals": "1.3.54-alpha.4",
|
|
26
|
+
"@tachybase/logger": "1.3.54-alpha.4",
|
|
27
|
+
"@tachybase/utils": "1.3.54-alpha.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/flat": "^5.0.5",
|