@mikro-orm/core 7.0.0-dev.264 → 7.0.0-dev.266

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.
@@ -456,7 +456,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
456
456
  /**
457
457
  * Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
458
458
  */
459
- populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entities: Entity, populate: readonly AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Entity extends object[] ? MergeLoaded<ArrayElement<Entity>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Entity, Naked, Hint, Fields, Excludes>>;
459
+ populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string = never, Excludes extends string = never>(entities: Entity, populate: readonly AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Entity extends object[] ? MergeLoaded<ArrayElement<Entity>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Entity, Naked, Hint, Fields, Excludes>>;
460
460
  /**
461
461
  * Returns new EntityManager instance with its own identity map
462
462
  */
@@ -8,7 +8,7 @@ import type { PopulatePath } from '../enums.js';
8
8
  export declare abstract class BaseEntity {
9
9
  isInitialized(): boolean;
10
10
  populated(populated?: boolean): void;
11
- populate<Entity extends this = this, Hint extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
11
+ populate<Entity extends this = this, Hint extends string = never, Fields extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
12
12
  toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
13
13
  /**
14
14
  * Converts the entity to a plain object representation.
@@ -129,7 +129,10 @@ export class EntityFactory {
129
129
  .filter(key => meta.properties[key]?.formula || [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(meta.properties[key]?.kind))
130
130
  .forEach(key => diff2[key] = data[key]);
131
131
  // rehydrated with the new values, skip those changed by user
132
- this.hydrate(entity, meta, diff2, options);
132
+ // use full hydration if the entity is already initialized, even if the caller used `initialized: false`
133
+ // (e.g. from createReference), otherwise scalar properties in diff2 won't be applied
134
+ const initialized = options.initialized || helper(entity).__initialized;
135
+ this.hydrate(entity, meta, diff2, initialized ? { ...options, initialized } : options);
133
136
  // we need to update the entity data only with keys that were not present before
134
137
  const nullVal = this.config.get('forceUndefined') ? undefined : null;
135
138
  Utils.keys(diff2).forEach(key => {
@@ -1,13 +1,13 @@
1
- import type { AnyEntity, ConnectionType, EntityName, EntityProperty, FilterQuery, PopulateOptions } from '../typings.js';
1
+ import type { AnyEntity, AutoPath, ConnectionType, EntityName, EntityProperty, FilterQuery, PopulateOptions } from '../typings.js';
2
2
  import type { EntityManager } from '../EntityManager.js';
3
3
  import { LoadStrategy, type LockMode, type PopulateHint, PopulatePath, type QueryOrderMap } from '../enums.js';
4
- import type { EntityField, FilterOptions } from '../drivers/IDatabaseDriver.js';
4
+ import type { FilterOptions } from '../drivers/IDatabaseDriver.js';
5
5
  import type { LoggingOptions } from '../logging/Logger.js';
6
- export type EntityLoaderOptions<Entity, Fields extends string = PopulatePath.ALL, Excludes extends string = never> = {
6
+ export interface EntityLoaderOptions<Entity, Fields extends string = PopulatePath.ALL, Excludes extends string = never> {
7
+ fields?: readonly AutoPath<Entity, Fields, `${PopulatePath.ALL}`>[];
8
+ exclude?: readonly AutoPath<Entity, Excludes>[];
7
9
  where?: FilterQuery<Entity>;
8
10
  populateWhere?: PopulateHint | `${PopulateHint}`;
9
- fields?: readonly EntityField<Entity, Fields>[];
10
- exclude?: readonly EntityField<Entity, Excludes>[];
11
11
  orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
12
12
  refresh?: boolean;
13
13
  validate?: boolean;
@@ -20,7 +20,7 @@ export type EntityLoaderOptions<Entity, Fields extends string = PopulatePath.ALL
20
20
  schema?: string;
21
21
  connectionType?: ConnectionType;
22
22
  logging?: LoggingOptions;
23
- };
23
+ }
24
24
  export declare class EntityLoader {
25
25
  private readonly em;
26
26
  private readonly metadata;
@@ -150,7 +150,7 @@ export declare class EntityRepository<Entity extends object> {
150
150
  /**
151
151
  * Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
152
152
  */
153
- populate<Ent extends Entity | Entity[], Hint extends string = never, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Fields extends string = '*', Excludes extends string = never>(entities: Ent, populate: AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Ent extends object[] ? MergeLoaded<ArrayElement<Ent>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Ent, Naked, Hint, Fields, Excludes>>;
153
+ populate<Ent extends Entity | Entity[], Hint extends string = never, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Fields extends string = never, Excludes extends string = never>(entities: Ent, populate: AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Ent extends object[] ? MergeLoaded<ArrayElement<Ent>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Ent, Naked, Hint, Fields, Excludes>>;
154
154
  /**
155
155
  * Creates new instance of given entity and populates it with given data.
156
156
  * The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
@@ -49,7 +49,7 @@ export declare class WrappedEntity<Entity extends object> {
49
49
  toJSON(...args: any[]): EntityDictionary<Entity>;
50
50
  assign<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
51
51
  init<Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
52
- populate<Hint extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
52
+ populate<Hint extends string = never, Fields extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
53
53
  hasPrimaryKey(): boolean;
54
54
  getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
55
55
  getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.264",
4
+ "version": "7.0.0-dev.266",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -58,10 +58,12 @@ export class EntityTransformer {
58
58
  continue;
59
59
  }
60
60
  const populated = root.isMarkedAsPopulated(meta.class, prop);
61
- const partiallyLoaded = root.isPartiallyLoaded(meta.class, prop);
62
- const isPrimary = includePrimaryKeys && meta.properties[prop].primary;
63
- if (!partiallyLoaded && !populated && !isPrimary) {
64
- continue;
61
+ if (!raw) {
62
+ const partiallyLoaded = root.isPartiallyLoaded(meta.class, prop);
63
+ const isPrimary = includePrimaryKeys && meta.properties[prop].primary;
64
+ if (!partiallyLoaded && !populated && !isPrimary) {
65
+ continue;
66
+ }
65
67
  }
66
68
  const cycle = root.visit(meta.class, prop);
67
69
  if (cycle && visited) {
package/typings.d.ts CHANGED
@@ -247,7 +247,7 @@ export interface IWrappedEntity<Entity extends object> {
247
247
  isInitialized(): boolean;
248
248
  isManaged(): boolean;
249
249
  populated(populated?: boolean): void;
250
- populate<Hint extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
250
+ populate<Hint extends string = never, Fields extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
251
251
  init<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Exclude>): Promise<Loaded<Entity, Hint, Fields, Exclude> | null>;
252
252
  toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
253
253
  toObject(): EntityDTO<Entity>;
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.0-dev.264';
126
+ static #ORM_VERSION = '7.0.0-dev.266';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */