@mikro-orm/core 7.2.11-dev.9 → 7.2.11

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.
package/EntityManager.js CHANGED
@@ -2489,6 +2489,11 @@ export class EntityManager {
2489
2489
  ? [meta.schema, meta.tableName, meta.discriminatorValue]
2490
2490
  : Utils.className(entityName);
2491
2491
  const key = [entityKey, method, opts, where];
2492
+ // filters of the root entity are part of `where`, but those of its relations are applied only when loading them
2493
+ const filterParams = this.getContext(false).#filterParams;
2494
+ if (options.filters !== false && Utils.hasObjectKeys(filterParams) && Utils.asArray(opts.populate).length > 0) {
2495
+ key.push({ filterParams });
2496
+ }
2492
2497
  // session context (row level security) scopes cached rows per tenant/role, avoiding cross-context serves
2493
2498
  const sessionContext = this.getContext(false).#sessionContext;
2494
2499
  if (sessionContext) {
@@ -39,6 +39,10 @@ export class EntityAssigner {
39
39
  if (DANGEROUS_PROPERTY_NAMES.includes(propName)) {
40
40
  return;
41
41
  }
42
+ // keys that are not entity properties must not replace methods of the entity, e.g. `toJSON`
43
+ if (!Object.hasOwn(props, propName) && typeof entity[propName] === 'function') {
44
+ return;
45
+ }
42
46
  let value = data[propName];
43
47
  const onlyProperties = options.onlyProperties && !(propName in props);
44
48
  const ignoreUndefined = options.ignoreUndefined === true && value === undefined;
@@ -88,7 +88,8 @@ export class AbstractNamingStrategy {
88
88
  * @inheritDoc
89
89
  */
90
90
  manyToManyPropertyName(ownerEntityName, targetEntityName, pivotTableName, ownerTableName, schemaName) {
91
- return this.columnNameToProperty(pivotTableName.replace(new RegExp('^' + ownerTableName + '_'), ''));
91
+ const prefix = ownerTableName + '_';
92
+ return this.columnNameToProperty(pivotTableName.startsWith(prefix) ? pivotTableName.slice(prefix.length) : pivotTableName);
92
93
  }
93
94
  /**
94
95
  * @inheritDoc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.11-dev.9",
3
+ "version": "7.2.11",
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",
@@ -270,7 +270,10 @@ export declare abstract class Platform {
270
270
  getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): ISchemaGenerator;
271
271
  /** Processes a date value before persisting, applying timezone or format conversions. */
272
272
  processDateProperty(value: unknown): string | number | Date;
273
- /** Wraps a table or column identifier with the platform-specific quote character. */
273
+ /**
274
+ * Wraps a table or column identifier with the platform-specific quote character. The result is meant to be embedded
275
+ * in a query template, so question marks in it are escaped as `\?` to not be mistaken for placeholders.
276
+ */
274
277
  quoteIdentifier(id: string | {
275
278
  toString: () => string;
276
279
  }, quote?: string): string;
@@ -279,7 +282,7 @@ export declare abstract class Platform {
279
282
  /** Quotes a string default value for DDL; dialects that escape with backslashes override this. */
280
283
  quoteDefaultValue(value: string): string;
281
284
  escape(value: any): string;
282
- /** Replaces `?` placeholders in SQL with quoted parameter values. */
285
+ /** Replaces `?` placeholders in SQL with quoted parameter values, `\?` stands for a literal question mark. */
283
286
  formatQuery(sql: string, params: readonly any[]): string;
284
287
  /** Deep-clones embeddable data and tags it for JSON serialization. */
285
288
  cloneEmbeddable<T>(data: T): T;
@@ -567,13 +567,20 @@ export class Platform {
567
567
  processDateProperty(value) {
568
568
  return value;
569
569
  }
570
- /** Wraps a table or column identifier with the platform-specific quote character. */
570
+ /**
571
+ * Wraps a table or column identifier with the platform-specific quote character. The result is meant to be embedded
572
+ * in a query template, so question marks in it are escaped as `\?` to not be mistaken for placeholders.
573
+ */
571
574
  quoteIdentifier(id, quote = '`') {
572
575
  const raw = Raw.getKnownFragment(id);
573
576
  if (raw) {
574
- return this.formatQuery(raw.sql, raw.params);
577
+ // fragments without params are kept as is, their placeholders can be bound by the outer query
578
+ return raw.params.length === 0 ? raw.sql : this.formatQuery(raw.sql, raw.params).replaceAll('?', '\\?');
575
579
  }
576
- const escaped = id.toString().replaceAll(quote, quote + quote);
580
+ const escaped = id
581
+ .toString()
582
+ .replaceAll(quote, quote + quote)
583
+ .replaceAll('?', '\\?');
577
584
  return `${quote}${escaped.replaceAll('.', `${quote}.${quote}`)}${quote}`;
578
585
  }
579
586
  /** Quotes a literal value for safe embedding in SQL. */
@@ -588,10 +595,10 @@ export class Platform {
588
595
  escape(value) {
589
596
  return value;
590
597
  }
591
- /** Replaces `?` placeholders in SQL with quoted parameter values. */
598
+ /** Replaces `?` placeholders in SQL with quoted parameter values, `\?` stands for a literal question mark. */
592
599
  formatQuery(sql, params) {
593
600
  if (params.length === 0) {
594
- return sql;
601
+ return sql.replaceAll('\\?', '?');
595
602
  }
596
603
  // fast string replace without regexps
597
604
  let j = 0;
@@ -599,7 +606,7 @@ export class Platform {
599
606
  let ret = '';
600
607
  if (sql.startsWith('?')) {
601
608
  if (sql[1] === '?') {
602
- ret += this.quoteIdentifier(params[j++]);
609
+ ret += this.quoteIdentifier(params[j++]).replaceAll('\\?', '?');
603
610
  pos = 2;
604
611
  }
605
612
  else {
@@ -618,7 +625,7 @@ export class Platform {
618
625
  pos = idx + 1;
619
626
  }
620
627
  else if (sql.substring(idx, idx + 2) === '??') {
621
- ret += sql.substring(pos, idx) + this.quoteIdentifier(params[j++]);
628
+ ret += sql.substring(pos, idx) + this.quoteIdentifier(params[j++]).replaceAll('\\?', '?');
622
629
  pos = idx + 2;
623
630
  }
624
631
  else {
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.11-dev.9';
156
+ static #ORM_VERSION = '7.2.11';
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}`;