Adjacency List in TypeORM not working properly

Viewed 70

I have been trying to create an Entity in TypeORM having an adjacency list as shown in this example.

Here is the code that I have written which is similar to the link above,

import {
  Entity,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
  Unique,
} from "typeorm";

@Entity()
export class Collection {
  @PrimaryGeneratedColumn()
  collectionId: number;

  @OneToMany((type) => Collection, (collection) => collection.parent)
  children: Collection[];

  @ManyToOne((type) => Collection, (collection) => collection.children, {
    onDelete: "CASCADE",
  })
  parent: Collection;
}

However, when I try to describe the table using the information_schema in the database, I am unable to see the children entity. All I can see are the collectionId and parent columns,

table_name column_name data_type
collection collectionId integer
collection parentCollectionId integer

I have been following the example given in the docs, but I am unable to understand why this is happening. If any more information is required, please let me know and I'll add it in the question.

Version information -

NestJS - Version 9.0.0
PostgreSQL - PostgreSQL 14.4
TypeScript - Version 4.3.5
@nestjs/typeorm - Version 9.0.0
typeorm - Version 0.3.7

0 Answers
Related