Omitting @OneToMany decorator is valid?
See original GitHub issueIssue 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?
Issue Analytics
- State:
- Created 5 years ago
- Comments:24 (10 by maintainers)
Top GitHub Comments
For future reference and googlers: #4190
You can now pass strings to the
@OneToMany
decorator:This fixes my OneToMany/ManyToOne relations, but for some reason does not fix the circular dep issue with OneToOne. Any ideas?