Closed veract-dev closed 5 months ago
You need to redefine the parent category as it rely on product category as well.
Tried both ways below still same issue.
models/product-category.ts
import { Column, Entity, Relation, Tree } from "typeorm"
import {
// alias the core entity to not cause a naming conflict
ProductCategory as MedusaProductCategory,
} from "@medusajs/medusa"
@Entity()
@Tree("materialized-path")
export class ProductCategory extends MedusaProductCategory {
@Column()
is_primary: boolean
parent_category: Relation<ProductCategory> | null;
}
import { Column, Entity, Relation, Tree } from "typeorm"
import {
// alias the core entity to not cause a naming conflict
ProductCategory as MedusaProductCategory,
} from "@medusajs/medusa"
@Entity()
@Tree("materialized-path")
export class ProductCategory extends MedusaProductCategory {
@Column()
is_primary: boolean
@Column({ type: 'character varying', nullable: true })
parent_category: Relation<ProductCategory> | null;
}
can you try with the following
@TreeParent()
@JoinColumn({ name: "parent_category_id" })
parent_category: Relation<ProductCategory> | null
// Typeorm also keeps track of the category's parent at all times.
@Column()
parent_category_id: string | null
@TreeChildren({ cascade: true })
category_children: Relation<ProductCategory>[]
Thank you it worked
Glad to ear :D
I'm trying to add 1 extra column is_primary in product-category entity, but got Cyclic dependency error
TypeORMError: Cyclic dependency: "ProductCategory" at visit (C:\Users\Public\Development\beanstalk\dev\bean-stalk-backend\node_modules\typeorm\persistence\SubjectTopoligicalSorter.js:147:23) at visit (C:\Users\Public\Development\beanstalk\dev\bean-stalk-backend\node_modules\typeorm\persistence\SubjectTopoligicalSorter.js:164:21) at SubjectTopoligicalSorter.toposort (C:\Users\Public\Development\beanstalk\dev\bean-stalk-backend\node_modules\typeorm\persistence\SubjectTopoligicalSorter.js:143:17) at SubjectTopoligicalSorter.sort (C:\Users\Public\Development\beanstalk\dev\bean-stalk-backend\node_modules\typeorm\persistence\SubjectTopoligicalSorter.js:53:45) at SubjectExecutor.execute (C:\Users\Public\Development\beanstalk\dev\bean-stalk-backend\node_modules\typeorm\persistence\SubjectExecutor.js:91:108) at EntityPersistExecutor.execute (C:\Users\Public\Development\beanstalk\dev\bean-stalk-backend\node_modules\typeorm\persistence\EntityPersistExecutor.js:140:36) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
CODE:
models/product-category.ts
repositories/product-category.ts
loader.ts
api/index.ts