Skip to content

[DOCS] Inverted decorators in "Adjacency list" example #6527

@manuelnucci

Description

@manuelnucci

Issue type:

[ ] question
[ ] bug report
[ ] feature request
[x] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

The decorators used in the "Adjacency list" could possibly be inverted.

Here's the example as I think is correct:

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

@Entity()
export class Category {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @Column()
    description: string;

    @ManyToOne(type => Category, category => category.children) // <-- each child has only one parent
    parent: Category;

    @OneToMany(type => Category, category => category.parent) // <-- each parent has one or more children
    children: Category[];
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions