@mikro-orm/core 7.2.9 → 7.2.10-dev.0

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.
@@ -545,7 +545,29 @@ export class EntityLoader {
545
545
  return;
546
546
  }
547
547
  options = { ...options, filters: QueryHelper.mergePropertyFilters(prop.filters, options.filters) };
548
+ // collections with unflushed changes, their items would be lost when reloading
549
+ const dirty = entities
550
+ .map(e => e[field])
551
+ .filter(coll => !options.refresh && Utils.isCollection(coll) && coll.isDirty())
552
+ .map(coll => [coll, coll.getItems(false)]);
553
+ const references = dirty.flatMap(([, items]) => items).filter(item => !helper(item).__initialized);
554
+ if (references.length > 0 && !populate.field.includes(':')) {
555
+ // loading the references directly keeps an initialized collection from being reloaded
556
+ await this.populateScalar(prop.targetMeta, Utils.unique(references), {
557
+ ...options,
558
+ where: {},
559
+ populateWhere: undefined,
560
+ fields: this.buildFields(options.fields, prop),
561
+ });
562
+ }
548
563
  const populated = await this.populateMany(entityName, entities, populate, options);
564
+ for (const [coll, items] of dirty) {
565
+ const lost = items.filter(item => !coll.contains(item, false));
566
+ // partially loaded collections can be readonly, as well as those that were not reloaded
567
+ if (lost.length > 0 && !coll.isPartial()) {
568
+ coll.add(lost);
569
+ }
570
+ }
549
571
  if (!populate.children && !populate.all) {
550
572
  return;
551
573
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.9",
3
+ "version": "7.2.10-dev.0",
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
  "keywords": [
6
6
  "data-mapper",
package/utils/Utils.js CHANGED
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
153
153
  /** Collection of general-purpose utility methods used throughout the ORM. */
154
154
  export class Utils {
155
155
  static PK_SEPARATOR = '~~~';
156
- static #ORM_VERSION = '7.2.9';
156
+ static #ORM_VERSION = '7.2.10-dev.0';
157
157
  /** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
158
158
  static getRlsSettingName(filterName, argName) {
159
159
  return `mikro.${filterName}.${argName}`;