Hi I have the following abstract TreeEntity
@Tree('closure-table')
@Entity()
export abstract class TreeNodeEntity<T extends TreeNodeEntity<T>> {
@PrimaryGeneratedColumn('uuid')
id: string;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@DeleteDateColumn()
deletedAt: Date;
@Column({ type: 'enum', enum: TreeNodeType, default: null })
type: TreeNodeType;
@Column()
name: string;
@Column({ unique: true, default: null })
slug: string;
@Column({ default: 0 })
order: number;
@Column({ default: null })
content: string;
@Column({ nullable: true })
parentId?: string;
@TreeParent()
parent?: T;
@TreeChildren()
children?: T[];
constructor(partial: Partial<TreeNodeEntity<T>>) {
Object.assign(this, partial);
}
}
And here is my CourseNodeEntity
that inherits it:
@Entity()
export class CourseNodeEntity extends TreeNodeEntity<CourseNodeEntity> {
@Column({ default: false })
isFree: boolean;
@OneToMany(() => FileEntity, (attachment) => attachment.courseNodeAttachments)
attachments?: FileEntity[];
@OneToOne(() => FileEntity)
@JoinColumn()
video?: FileEntity;
@ManyToOne(() => CourseEntity, (target) => target.nodes)
target: CourseEntity;
@Column({ default: 0 })
homeworksCount: number;
constructor(partial: Partial<CourseNodeEntity>) {
super(partial);
Object.assign(this, partial);
}
}
Unfortunately there is an error when I’m trying to add a CourseNode
with non-null parentId (
inserting or modifying on table 'course_node_entity' foreign key violation 'FK_15887c4f37b41f4b23d5bc6ac2b'
):
Any ideas how to make it works or inheritance will not work with Tree entities and relations in general?