@nocobase/database 2.2.0-beta.16 → 2.2.0-beta.17

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.
@@ -50,6 +50,23 @@ const pushAttribute = /* @__PURE__ */ __name((node, attribute) => {
50
50
  node.attributes.push(attribute);
51
51
  }
52
52
  }, "pushAttribute");
53
+ const getRootModelOrderFields = /* @__PURE__ */ __name((node) => {
54
+ if (!import_lodash.default.isArray(node.order)) {
55
+ return [];
56
+ }
57
+ const fields = [];
58
+ for (const orderItem of node.order) {
59
+ if (!import_lodash.default.isArray(orderItem) || orderItem.length !== 2 || !import_lodash.default.isString(orderItem[0])) {
60
+ continue;
61
+ }
62
+ const fieldName = orderItem[0];
63
+ const attribute = node.model.rawAttributes[fieldName] || Object.values(node.model.rawAttributes).find((item) => item.field === fieldName);
64
+ if (attribute) {
65
+ fields.push(attribute.field || fieldName);
66
+ }
67
+ }
68
+ return fields;
69
+ }, "getRootModelOrderFields");
53
70
  const EagerLoadingNodeProto = {
54
71
  afterBuild(db) {
55
72
  const collection = db.modelCollection.get(this.model);
@@ -218,11 +235,15 @@ const _EagerLoadingTree = class _EagerLoadingTree {
218
235
  if (!primaryKeyField) {
219
236
  throw new Error(`Model ${node.model.name} does not have primary key`);
220
237
  }
238
+ const group = [`${node.model.name}.${primaryKeyField}`];
239
+ if (this.db.inDialect("mssql") || this.db.isMySQLCompatibleDialect()) {
240
+ group.push(...getRootModelOrderFields(node).map((field) => `${node.model.name}.${field}`));
241
+ }
221
242
  const ids2 = (await node.model.findAll({
222
243
  ...this.rootQueryOptions,
223
244
  includeIgnoreAttributes: false,
224
245
  attributes: [primaryKeyField],
225
- group: `${node.model.name}.${primaryKeyField}`,
246
+ group: import_lodash.default.uniq(group),
226
247
  transaction,
227
248
  include: (0, import_utils.processIncludes)(includeForFilter, node.model),
228
249
  raw: true
@@ -128,6 +128,8 @@ const _BelongsToManyField = class _BelongsToManyField extends import_relation_fi
128
128
  let Through;
129
129
  if (database.hasCollection(through)) {
130
130
  Through = database.getCollection(through);
131
+ Through.options.sourceCollectionName ??= this.collection.name;
132
+ Through.options.targetCollectionName ??= this.target;
131
133
  } else {
132
134
  const throughCollectionOptions = {
133
135
  name: through,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.2.0-beta.16",
3
+ "version": "2.2.0-beta.17",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "2.2.0-beta.16",
10
- "@nocobase/utils": "2.2.0-beta.16",
9
+ "@nocobase/logger": "2.2.0-beta.17",
10
+ "@nocobase/utils": "2.2.0-beta.17",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "49d9bd2e21122eab9435f128375828b8c5bb4c07"
41
+ "gitHead": "d7a69c4f47fe38b17a2ce1408258902cf64f6c83"
42
42
  }