@mikro-orm/knex 5.8.4-dev.4 → 5.8.4-dev.5

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.
@@ -133,7 +133,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
133
133
  return null;
134
134
  }
135
135
  if (qb) {
136
+ // here we map the aliased results (cartesian product) to an object graph
136
137
  this.mapJoinedProps(ret, meta, populate, qb, ret, map);
138
+ // we need to remove the cycles from the mapped values
139
+ core_1.Utils.removeCycles(ret, meta);
137
140
  }
138
141
  return ret;
139
142
  }
@@ -148,7 +151,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
148
151
  const meta2 = this.metadata.find(relation.type);
149
152
  const path = parentJoinPath ? `${parentJoinPath}.${relation.name}` : `${meta.name}.${relation.name}`;
150
153
  const relationAlias = qb.getAliasForJoinPath(path);
151
- const relationPojo = {};
154
+ let relationPojo = {};
152
155
  // If the primary key value for the relation is null, we know we haven't joined to anything
153
156
  // and therefore we don't return any record (since all values would be null)
154
157
  const hasPK = meta2.primaryKeys.every(pk => meta2.properties[pk].fieldNames.every(name => {
@@ -176,7 +179,16 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
176
179
  delete root[alias];
177
180
  }
178
181
  });
179
- const key = `${meta.name}-${(core_1.Utils.getCompositeKeyHash(result, meta))}`;
182
+ const key = `${meta.name}-${core_1.Utils.getCompositeKeyHash(result, meta)}`;
183
+ const key2 = `${meta2.name}-${core_1.Utils.getCompositeKeyHash(relationPojo, meta2)}`;
184
+ if (map[key2]) {
185
+ const old = map[key2];
186
+ Object.assign(old, relationPojo);
187
+ relationPojo = old;
188
+ }
189
+ else {
190
+ map[key2] = relationPojo;
191
+ }
180
192
  if (map[key]) {
181
193
  result[relation.name] = map[key][relation.name];
182
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.8.4-dev.4",
3
+ "version": "5.8.4-dev.5",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,9 +66,9 @@
66
66
  "@mikro-orm/core": "^5.8.3"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "~5.8.4-dev.4",
70
- "@mikro-orm/entity-generator": "~5.8.4-dev.4",
71
- "@mikro-orm/migrations": "~5.8.4-dev.4",
69
+ "@mikro-orm/core": "~5.8.4-dev.5",
70
+ "@mikro-orm/entity-generator": "~5.8.4-dev.5",
71
+ "@mikro-orm/migrations": "~5.8.4-dev.5",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",