chore(): Remove default limit from the build query (#9257)
* chore(): Remove default limit from the build query * rm take: null * fix tests * fix tests * fix db usage * fix typo * rm unsused template arg * fixes * fixes * fixes * fixes * fixes * fixes * fixes
This commit is contained in:
@@ -20,7 +20,7 @@ class RecursiveEntity1 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, {
|
||||
@@ -44,7 +44,7 @@ class RecursiveEntity2 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => RecursiveEntity1, {
|
||||
@@ -64,7 +64,7 @@ class Entity1 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => Entity2, (entity2) => entity2.entity1, {
|
||||
@@ -89,7 +89,7 @@ class Entity2 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => Entity1, { mapToPk: true })
|
||||
@@ -111,7 +111,7 @@ class DeepRecursiveEntity1 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, {
|
||||
@@ -136,7 +136,7 @@ class DeepRecursiveEntity2 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity1)
|
||||
@@ -163,7 +163,7 @@ class DeepRecursiveEntity3 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity1, {
|
||||
@@ -187,7 +187,7 @@ class DeepRecursiveEntity4 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity1)
|
||||
@@ -214,7 +214,7 @@ class InternalCircularDependencyEntity1 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(
|
||||
@@ -226,7 +226,7 @@ class InternalCircularDependencyEntity1 {
|
||||
)
|
||||
children = new Collection<InternalCircularDependencyEntity1>(this)
|
||||
|
||||
@ManyToOne(() => InternalCircularDependencyEntity1)
|
||||
@ManyToOne(() => InternalCircularDependencyEntity1, { nullable: true })
|
||||
parent: Rel<InternalCircularDependencyEntity1>
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ class Entity1WithUnDecoratedProp {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, {
|
||||
@@ -271,7 +271,7 @@ class Entity2WithUnDecoratedProp {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true })
|
||||
@@ -293,7 +293,7 @@ class SearchableEntity1 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@Searchable()
|
||||
@@ -321,7 +321,7 @@ class SearchableEntity2 {
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property()
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@Searchable()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||
|
||||
export const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
export function getDatabaseURL(dbName): string {
|
||||
return `postgres://${DB_USERNAME}${
|
||||
DB_PASSWORD ? `:${DB_PASSWORD}` : ""
|
||||
}@${DB_HOST}/${dbName}`
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
import {
|
||||
Collection,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
import { Searchable } from "../../decorators/searchable"
|
||||
|
||||
// Circular dependency one level
|
||||
@Entity()
|
||||
class RecursiveEntity1 {
|
||||
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity2 = new Collection<RecursiveEntity2>(this)
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class RecursiveEntity2 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: RecursiveEntity1
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity1 = props.entity1
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => RecursiveEntity1, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity1: Rel<RecursiveEntity1>
|
||||
}
|
||||
|
||||
// No circular dependency
|
||||
@Entity()
|
||||
class Entity1 {
|
||||
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => Entity2, (entity2) => entity2.entity1, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity2 = new Collection<Entity2>(this)
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class Entity2 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: Rel<Entity1>
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity1 = props.entity1
|
||||
this.entity1_id = props.entity1.id
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => Entity1, { mapToPk: true })
|
||||
entity1_id: string
|
||||
|
||||
@ManyToOne(() => Entity1, { persist: false })
|
||||
entity1: Entity1
|
||||
}
|
||||
|
||||
// Circular dependency deep level
|
||||
|
||||
@Entity()
|
||||
class DeepRecursiveEntity1 {
|
||||
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity2 = new Collection<DeepRecursiveEntity2>(this)
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class DeepRecursiveEntity2 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: Rel<DeepRecursiveEntity1>
|
||||
entity3: Rel<DeepRecursiveEntity3>
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity3 = props.entity3
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity1)
|
||||
entity1: DeepRecursiveEntity1
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity3, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity3: Rel<DeepRecursiveEntity3>
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class DeepRecursiveEntity3 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: Rel<DeepRecursiveEntity1>
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity1 = props.entity1
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity1, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity1: Rel<DeepRecursiveEntity1>
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class DeepRecursiveEntity4 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: Rel<DeepRecursiveEntity1>
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity1 = props.entity1
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => DeepRecursiveEntity1)
|
||||
entity1: Rel<DeepRecursiveEntity1>
|
||||
}
|
||||
|
||||
// Internal circular dependency
|
||||
|
||||
@Entity()
|
||||
class InternalCircularDependencyEntity1 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
parent?: InternalCircularDependencyEntity1
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
|
||||
if (props.parent) {
|
||||
this.parent = props.parent
|
||||
}
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(
|
||||
() => InternalCircularDependencyEntity1,
|
||||
(entity) => entity.parent,
|
||||
{
|
||||
cascade: ["soft-remove"] as any,
|
||||
}
|
||||
)
|
||||
children = new Collection<InternalCircularDependencyEntity1>(this)
|
||||
|
||||
@ManyToOne(() => InternalCircularDependencyEntity1, { nullable: true })
|
||||
parent: Rel<InternalCircularDependencyEntity1>
|
||||
}
|
||||
|
||||
// With un decorated prop
|
||||
|
||||
@Entity()
|
||||
class Entity1WithUnDecoratedProp {
|
||||
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
}
|
||||
|
||||
unknownProp: string
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, {
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
entity2 = new Collection<Entity2WithUnDecoratedProp>(this)
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class Entity2WithUnDecoratedProp {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: Rel<Entity1WithUnDecoratedProp>
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity1 = props.entity1
|
||||
this.entity1_id = props.entity1.id
|
||||
}
|
||||
|
||||
unknownProp: string
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true })
|
||||
entity1_id: string
|
||||
|
||||
@ManyToOne(() => Entity1WithUnDecoratedProp, { persist: false })
|
||||
entity1: Rel<Entity1WithUnDecoratedProp>
|
||||
}
|
||||
|
||||
// Searchable fields
|
||||
|
||||
@Entity()
|
||||
class SearchableEntity1 {
|
||||
constructor(props: { id: string; deleted_at: Date | null }) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@Searchable()
|
||||
@Property()
|
||||
searchableField: string
|
||||
|
||||
@Searchable()
|
||||
@OneToMany(() => SearchableEntity2, (entity2) => entity2.entity1)
|
||||
entity2 = new Collection<SearchableEntity2>(this)
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class SearchableEntity2 {
|
||||
constructor(props: {
|
||||
id: string
|
||||
deleted_at: Date | null
|
||||
entity1: SearchableEntity1
|
||||
}) {
|
||||
this.id = props.id
|
||||
this.deleted_at = props.deleted_at
|
||||
this.entity1 = props.entity1
|
||||
this.entity1_id = props.entity1.id
|
||||
}
|
||||
|
||||
@PrimaryKey()
|
||||
id: string
|
||||
|
||||
@Property({ nullable: true })
|
||||
deleted_at: Date | null
|
||||
|
||||
@Searchable()
|
||||
@Property()
|
||||
searchableField: string
|
||||
|
||||
@ManyToOne(() => SearchableEntity1, { mapToPk: true })
|
||||
entity1_id: string
|
||||
|
||||
@ManyToOne(() => SearchableEntity1, { persist: false })
|
||||
entity1: Rel<SearchableEntity1>
|
||||
}
|
||||
|
||||
export {
|
||||
DeepRecursiveEntity1,
|
||||
DeepRecursiveEntity2,
|
||||
DeepRecursiveEntity3,
|
||||
DeepRecursiveEntity4,
|
||||
Entity1,
|
||||
Entity1WithUnDecoratedProp,
|
||||
Entity2,
|
||||
Entity2WithUnDecoratedProp,
|
||||
InternalCircularDependencyEntity1,
|
||||
RecursiveEntity1,
|
||||
RecursiveEntity2,
|
||||
SearchableEntity1,
|
||||
SearchableEntity2,
|
||||
}
|
||||
+4
-18
@@ -18,23 +18,9 @@ import { dropDatabase } from "pg-god"
|
||||
import { MikroOrmBigNumberProperty } from "../../big-number-field"
|
||||
import BigNumber from "bignumber.js"
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||
const DB_NAME = "mikroorm-integration-1"
|
||||
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
export function getDatabaseURL(): string {
|
||||
return `postgres://${DB_USERNAME}${
|
||||
DB_PASSWORD ? `:${DB_PASSWORD}` : ""
|
||||
}@${DB_HOST}/${DB_NAME}`
|
||||
}
|
||||
const dbName = "mikroorm-integration-1"
|
||||
|
||||
jest.setTimeout(300000)
|
||||
@Entity()
|
||||
@@ -153,13 +139,13 @@ describe("mikroOrmRepository", () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await dropDatabase(
|
||||
{ databaseName: DB_NAME, errorIfNonExist: false },
|
||||
{ databaseName: dbName, errorIfNonExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
entities: [Entity1, Entity2],
|
||||
clientUrl: getDatabaseURL(),
|
||||
clientUrl: getDatabaseURL(dbName),
|
||||
type: "postgresql",
|
||||
})
|
||||
|
||||
|
||||
+27
-7
@@ -1,4 +1,4 @@
|
||||
import { mikroOrmUpdateDeletedAtRecursively } from "../utils"
|
||||
import { mikroOrmUpdateDeletedAtRecursively } from "../../utils"
|
||||
import { MikroORM } from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import {
|
||||
@@ -12,6 +12,10 @@ import {
|
||||
RecursiveEntity1,
|
||||
RecursiveEntity2,
|
||||
} from "../__fixtures__/utils"
|
||||
import { dropDatabase } from "pg-god"
|
||||
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||
|
||||
const dbName = "mikroorm-utils-integration-1"
|
||||
|
||||
jest.mock("@mikro-orm/core", () => ({
|
||||
...jest.requireActual("@mikro-orm/core"),
|
||||
@@ -29,6 +33,11 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
||||
let orm!: MikroORM
|
||||
|
||||
beforeEach(async () => {
|
||||
await dropDatabase(
|
||||
{ databaseName: dbName, errorIfNonExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
entities: [
|
||||
Entity1,
|
||||
@@ -41,13 +50,19 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
||||
DeepRecursiveEntity4,
|
||||
InternalCircularDependencyEntity1,
|
||||
],
|
||||
dbName: "test",
|
||||
clientUrl: getDatabaseURL(dbName),
|
||||
type: "postgresql",
|
||||
})
|
||||
|
||||
const generator = orm.getSchemaGenerator()
|
||||
await generator.ensureDatabase()
|
||||
await generator.createSchema()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await orm.close()
|
||||
const generator = orm.getSchemaGenerator()
|
||||
await generator.dropSchema()
|
||||
await orm.close(true)
|
||||
})
|
||||
|
||||
it("should successfully mark the entities deleted_at recursively", async () => {
|
||||
@@ -59,12 +74,14 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
||||
entity1: entity1,
|
||||
})
|
||||
entity1.entity2.add(entity2)
|
||||
manager.persist(entity1)
|
||||
manager.persist(entity2)
|
||||
|
||||
const deletedAt = new Date()
|
||||
await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt)
|
||||
|
||||
expect(entity1.deleted_at).toEqual(deletedAt)
|
||||
expect(entity2.deleted_at).toEqual(deletedAt)
|
||||
expect(!!entity1.deleted_at).toEqual(true)
|
||||
expect(!!entity2.deleted_at).toEqual(true)
|
||||
})
|
||||
|
||||
it("should successfully mark the entities deleted_at recursively with internal parent/child relation", async () => {
|
||||
@@ -80,11 +97,14 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
||||
parent: entity1,
|
||||
})
|
||||
|
||||
manager.persist(entity1)
|
||||
manager.persist(childEntity1)
|
||||
|
||||
const deletedAt = new Date()
|
||||
await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt)
|
||||
|
||||
expect(entity1.deleted_at).toEqual(deletedAt)
|
||||
expect(childEntity1.deleted_at).toEqual(deletedAt)
|
||||
expect(!!entity1.deleted_at).toEqual(true)
|
||||
expect(!!childEntity1.deleted_at).toEqual(true)
|
||||
})
|
||||
|
||||
it("should throw an error when a circular dependency is detected", async () => {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EntityMetadata, FindOptions, wrap } from "@mikro-orm/core"
|
||||
import { Collection, EntityMetadata, FindOptions, wrap } from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { buildQuery } from "../../modules-sdk/build-query"
|
||||
|
||||
@@ -92,28 +92,29 @@ async function performCascadingSoftDeletion<T>(
|
||||
)
|
||||
}
|
||||
|
||||
entityRelation = await retrieveEntity()
|
||||
entityRelation = entityRelation[relation.name]
|
||||
if (!entityRelation) {
|
||||
// Fixes the case of many to many through pivot table
|
||||
entityRelation = await retrieveEntity()
|
||||
if (!entityRelation) {
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
const isCollection = "toArray" in entityRelation
|
||||
let relationEntities: any[] = []
|
||||
|
||||
if (isCollection) {
|
||||
if (!entityRelation.isInitialized()) {
|
||||
if (!(entityRelation as Collection<any, any>).isInitialized()) {
|
||||
entityRelation = await retrieveEntity()
|
||||
entityRelation = entityRelation[relation.name]
|
||||
}
|
||||
relationEntities = entityRelation.getItems()
|
||||
} else {
|
||||
const wrappedEntity = wrap(entityRelation)
|
||||
const initializedEntityRelation = wrappedEntity.isInitialized()
|
||||
? entityRelation
|
||||
: await wrap(entityRelation).init()
|
||||
|
||||
let initializedEntityRelation = entityRelation
|
||||
if (!wrappedEntity.isInitialized()) {
|
||||
initializedEntityRelation = await wrap(entityRelation).init()
|
||||
}
|
||||
|
||||
relationEntities = [initializedEntityRelation]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user