@mikro-orm/knex 6.0.0-dev.270 → 6.0.0-dev.271

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.
@@ -231,31 +231,41 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
231
231
  relationPojo[prop.name] = root[alias];
232
232
  }
233
233
  });
234
- const props = ref
234
+ const targetProps = ref
235
235
  ? meta2.getPrimaryProps()
236
236
  : meta2.props.filter(prop => this.platform.shouldHaveColumn(prop, hint.children || []));
237
- for (const prop1 of props) {
238
- if (prop1.fieldNames.length > 1) { // composite keys
239
- const fk = prop1.fieldNames.map(name => root[`${relationAlias}__${name}`]);
240
- relationPojo[prop1.name] = core_1.Utils.mapFlatCompositePrimaryKey(fk, prop1);
237
+ for (const prop of targetProps) {
238
+ if (prop.fieldNames.length > 1) { // composite keys
239
+ const fk = prop.fieldNames.map(name => root[`${relationAlias}__${name}`]);
240
+ relationPojo[prop.name] = core_1.Utils.mapFlatCompositePrimaryKey(fk, prop);
241
241
  }
242
- else if (prop1.runtimeType === 'Date') {
243
- const alias = `${relationAlias}__${prop1.fieldNames[0]}`;
244
- relationPojo[prop1.name] = (typeof root[alias] === 'string' ? new Date(root[alias]) : root[alias]);
242
+ else if (prop.runtimeType === 'Date') {
243
+ const alias = `${relationAlias}__${prop.fieldNames[0]}`;
244
+ relationPojo[prop.name] = (typeof root[alias] === 'string' ? new Date(root[alias]) : root[alias]);
245
245
  }
246
246
  else {
247
- const alias = `${relationAlias}__${prop1.fieldNames[0]}`;
248
- relationPojo[prop1.name] = root[alias];
247
+ const alias = `${relationAlias}__${prop.fieldNames[0]}`;
248
+ relationPojo[prop.name] = root[alias];
249
+ if (prop.kind === core_1.ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
250
+ const item = (0, core_1.parseJsonSafe)(relationPojo[prop.name]);
251
+ if (Array.isArray(item)) {
252
+ relationPojo[prop.name] = item.map(row => row == null ? row : this.comparator.mapResult(prop.type, row));
253
+ }
254
+ else {
255
+ relationPojo[prop.name] = item == null ? item : this.comparator.mapResult(prop.type, item);
256
+ }
257
+ }
249
258
  }
250
259
  }
251
260
  // properties can be mapped to multiple places, e.g. when sharing a column in multiple FKs,
252
261
  // so we need to delete them after everything is mapped from given level
253
- for (const prop1 of props) {
254
- prop1.fieldNames.map(name => delete root[`${relationAlias}__${name}`]);
262
+ for (const prop of targetProps) {
263
+ prop.fieldNames.map(name => delete root[`${relationAlias}__${name}`]);
255
264
  }
256
265
  if (ref) {
257
266
  const tmp = Object.values(relationPojo);
258
- relationPojo = meta2.compositePK ? tmp : tmp[0];
267
+ /* istanbul ignore next */
268
+ relationPojo = (meta2.compositePK ? tmp : tmp[0]);
259
269
  }
260
270
  if ([core_1.ReferenceKind.MANY_TO_MANY, core_1.ReferenceKind.ONE_TO_MANY].includes(prop.kind)) {
261
271
  result[prop.name] ??= [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.0.0-dev.270",
3
+ "version": "6.0.0-dev.271",
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,6 +66,6 @@
66
66
  "@mikro-orm/core": "^5.9.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.0-dev.270"
69
+ "@mikro-orm/core": "6.0.0-dev.271"
70
70
  }
71
71
  }