Запрос Typeorm завершается сбоем при добавлении связи
Привет, ребята, я использую medusajs/typeorm, и в настоящее время я столкнулся со странной проблемой: использование того же репозитория для получения некоторых данных работает отлично, когда отношения не добавляются, но когда добавляется стремление или отношения добавляются в репозиторий, выдается странная ошибка:
Вот файлы:
- Модели:
import { Column, Entity, OneToMany, ManyToOne, JoinColumn } from "typeorm"
import { BaseEntity } from "@medusajs/medusa"
import { QuantityConstraint } from "../types/quantity-constraint"
import { ModifierOption } from "./modifier-option"
import { ProductVariant } from "./product-variant"
@Entity()
export class ModifiersGroup extends BaseEntity {
@Column()
title: string;
@Column({ nullable: true })
subtitle: string | null;
@Column({ nullable: true })
description: string | null;
@Column({ type: "int", nullable: true })
rank: number | null;
@Column({ nullable: true })
image_url: string | null
@Column({ type: "bool", default: false})
is_disabled: boolean
@Column({ type: "simple-json", nullable: true })
quantity_info: QuantityConstraint | null
@OneToMany(() => ModifierOption, (modifierOption) => modifierOption.group, {
cascade: true,
eager: true
})
options: ModifierOption[]
@ManyToOne(() => ProductVariant, (productVariant) => productVariant.modifiers_groups)
@JoinColumn({ name: "variant_id", referencedColumnName: "id" })
variant: ProductVariant
}
import {
Column,
Entity,
ManyToOne,
JoinColumn
} from "typeorm"
import { BaseEntity } from "@medusajs/medusa"
import { ModifiersGroup } from "./modifiers-group";
import { MoneyAmount } from "./money-amount";
import { QuantityConstraint } from "../types/quantity-constraint";
@Entity()
export class ModifierOption extends BaseEntity {
@Column()
title: string;
@Column({ nullable: true })
subtitle: string | null;
@Column({ nullable: true })
description: string | null;
@Column({ type: "int", nullable: true })
rank: number | null;
@Column({ nullable: true })
image_url: string | null
@Column({type: "bool", default: false})
is_disabled: boolean
@Column({ type: "simple-json", nullable: true })
prices: MoneyAmount[]
@Column({ type: "simple-json", nullable: true })
quantity_info: QuantityConstraint | null
@ManyToOne(() => ModifiersGroup, (modifiersGroup) => modifiersGroup.options)
@JoinColumn({ name: "modifiers_group_id", referencedColumnName: "id" })
group: ModifiersGroup
}
- Репозиторий:
import { FindOptionsWhere } from "typeorm"
import { ModifiersGroup } from "../models/modifiers-group"
import {
dataSource,
} from "@medusajs/medusa/dist/loaders/database"
export const ModifiersGroupRepository = dataSource
.getRepository(ModifiersGroup)
.extend({
async retrieveOneByVariant(variantId: string): Promise<ModifiersGroup | null> {
return this.findOne(
{
where: {
variant: { "id": variantId }
}
}
)
}
})
export default ModifiersGroupRepository
- Ошибка
023-05-11 23:15:42 SyntaxError: Unexpected token , in JSON at position 68
2023-05-11 23:15:42 at JSON.parse (<anonymous>)
2023-05-11 23:15:42 at DateUtils.stringToSimpleJson (/app/medusa/node_modules/typeorm/util/DateUtils.js:185:49)
2023-05-11 23:15:42 at PostgresDriver.prepareHydratedValue (/app/medusa/node_modules/typeorm/driver/postgres/PostgresDriver.js:518:43)
2023-05-11 23:15:42 at /app/medusa/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js:132:55
2023-05-11 23:15:42 at Array.forEach (<anonymous>)
2023-05-11 23:15:42 at RawSqlResultsToEntityTransformer.transformColumns (/app/medusa/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js:118:26)
2023-05-11 23:15:42 at RawSqlResultsToEntityTransformer.transformRawResultsGroup (/app/medusa/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js:98:33)
2023-05-11 23:15:42 at /app/medusa/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js:33:33
2023-05-11 23:15:42 at Map.forEach (<anonymous>)
2023-05-11 23:15:42 at RawSqlResultsToEntityTransformer.transform (/app/medusa/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js:32:15)```
I tried, with eager on the model as is now, also adding relations: { options: true} in the repository, same error.