@tachybase/database 1.3.54-alpha.6 → 1.3.54-alpha.7

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,7 +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
+ var _a, _b;
68
68
  let { foreignKey, targetKey } = this.options;
69
69
  if (!targetKey) {
70
70
  targetKey = this.TargetModel.primaryKeyAttribute;
@@ -74,23 +74,7 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
74
74
  }
75
75
  const targetKeyAttribute = (_a = this.TargetModel.rawAttributes) == null ? void 0 : _a[targetKey];
76
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
- );
90
77
  if (!foreignKeyAttribute || !targetKeyAttribute) {
91
- (_h = this.context.database.logger) == null ? void 0 : _h.warn(
92
- `[BelongsToField.checkAssociationKeys] Skipping check - foreignKeyAttribute: ${!!foreignKeyAttribute}, targetKeyAttribute: ${!!targetKeyAttribute}`
93
- );
94
78
  return;
95
79
  }
96
80
  const foreignKeyType = foreignKeyAttribute.type.constructor.toString();
@@ -102,27 +86,9 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
102
86
  }
103
87
  }
104
88
  bind() {
105
- var _a, _b, _c;
106
89
  const { database, collection } = this.context;
107
90
  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
- );
122
91
  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
- );
126
92
  database.addPendingField(this);
127
93
  return false;
128
94
  }
@@ -130,20 +96,11 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
130
96
  if (collection.model.associations[this.name]) {
131
97
  delete collection.model.associations[this.name];
132
98
  }
133
- const belongsToOptions = {
99
+ const association = collection.model.belongsTo(Target, {
134
100
  as: this.name,
135
101
  constraints: false,
136
102
  ...(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
145
103
  });
146
- const association = collection.model.belongsTo(Target, belongsToOptions);
147
104
  database.removePendingField(this);
148
105
  if (!this.options.foreignKey) {
149
106
  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.6",
3
+ "version": "1.3.54-alpha.7",
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/utils": "1.3.54-alpha.6",
26
- "@tachybase/logger": "1.3.54-alpha.6",
27
- "@tachybase/globals": "1.3.54-alpha.6"
25
+ "@tachybase/utils": "1.3.54-alpha.7",
26
+ "@tachybase/logger": "1.3.54-alpha.7",
27
+ "@tachybase/globals": "1.3.54-alpha.7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/flat": "^5.0.5",