mikro-orm
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -25,2 +25,3 @@ "use strict"; | ||
const cond = {}; | ||
const order = []; | ||
if (this.property.reference === BaseEntity_1.ReferenceType.ONE_TO_MANY) { | ||
@@ -31,3 +32,4 @@ cond[this.property.fk] = this.owner._id; | ||
if (this.property.owner) { | ||
cond._id = { $in: this.items.map(item => item._id) }; | ||
const order = this.items.map(item => item._id); | ||
cond._id = { $in: order }; | ||
} | ||
@@ -41,2 +43,8 @@ else { | ||
const items = await em.find(this.property.type, cond); | ||
// re-order items when searching with `$in` operator | ||
if (this.property.reference === BaseEntity_1.ReferenceType.MANY_TO_MANY && this.property.owner) { | ||
items.sort((a, b) => { | ||
return order.indexOf(a._id) - order.indexOf(b._id); | ||
}); | ||
} | ||
this.items.push(...items); | ||
@@ -43,0 +51,0 @@ this.initialized = true; |
@@ -30,2 +30,3 @@ import { ObjectID } from 'bson'; | ||
const cond = {} as any; | ||
const order = [] as ObjectID[]; | ||
@@ -36,3 +37,4 @@ if (this.property.reference === ReferenceType.ONE_TO_MANY) { | ||
if (this.property.owner) { | ||
cond._id = { $in: this.items.map(item => item._id) }; | ||
const order = this.items.map(item => item._id); | ||
cond._id = { $in: order }; | ||
} else { | ||
@@ -46,2 +48,10 @@ cond[this.property.mappedBy] = this.owner._id; | ||
const items = await em.find<T>(this.property.type, cond); | ||
// re-order items when searching with `$in` operator | ||
if (this.property.reference === ReferenceType.MANY_TO_MANY && this.property.owner) { | ||
items.sort((a: BaseEntity, b: BaseEntity) => { | ||
return order.indexOf(a._id) - order.indexOf(b._id); | ||
}); | ||
} | ||
this.items.push(...items); | ||
@@ -48,0 +58,0 @@ this.initialized = true; |
{ | ||
"name": "mikro-orm", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "Simple typescript mongo ORM for node.js based on data-mapper, unit-of-work and identity-map patterns", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145727
3320