Skip to content

Omitting @OneToMany decorator is valid? #2059

@MeMeMax

Description

@MeMeMax

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

export class User {
    @PrimaryGeneratedColumn()
    public id: number;

    @Column({
        unique: true
    })
    public email: string;

    @Column()
    public password: string;

    @ManyToOne(type => Home, home => home.id)
    public home: Home;

    @OneToMany(type => Electricity, electricity => electricity.home)
    public electricity: Electricity[];

    @OneToMany(type => Gas, gas => gas.home)
    public gas: Gas[];

    @OneToMany(type => Water, water => water.home)
    public water: Water[];
}
export class Meter {
    @PrimaryGeneratedColumn()
    public id: number;

    @Column("decimal", { precision: 15, scale: 3 })
    public value: number;

    @Column()
    public date: Date;

    @ManyToOne(type => User, user => user.id)
    public user: User;

    @ManyToOne(type => Home, home => home.id)
    public home: Home;
}
export class Home {
    @PrimaryGeneratedColumn()
    public id: number;

    @Column()
    public street: string;

    @Column()
    public town: string;

    @Column()
    public postalcode: number;

    @Column()
    public streetnumber: number;

    @OneToMany(type => User, user => user.id)
    public user: User[];

    @OneToMany(type => MeterCounter, counter => counter.id)
    public counter: MeterCounter[];

    @OneToMany(type => Electricity, electricity => electricity.home)
    public electricity: Electricity[];

    @OneToMany(type => Gas, gas => gas.home)
    public gas: Gas[];

    @OneToMany(type => Water, water => water.home)
    public water: Water[];
}

I got these Entities. The Meter Entity has two foreign keys: UserId and HomeId. It looks like I am creating a circular dependency as I get this error (Gas, Water and Electricity are just empty Entities which inherit from Meter):

export class Gas extends Meter { }
TypeError: Class extends value undefined is not a constructor or null

However when I omit the @onetomany decorator I don´t get the error and everything works fine. Is that a valid behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions