#Many-to-one / one-to-many relations don't work

7 messages · Page 1 of 1 (latest)

woven ocean
#

Hello! I'm trying to develop some work with user with multi language feature.
I have this tables (1 photo).
And this is my implementation:

@Entity({name: "user"})
export class UserEntity extends AbstractEntity {
    @Column({nullable: true})
    public avatar: string;

    @Column()
    public auth0_sub: string;

    @OneToMany(() => UserTranslateEntity, (userTranslate) => userTranslate.user)
    public translations: UserTranslateEntity[];
}
@Entity({name: "userTranslate"})
export class UserTranslateEntity extends AbstractEntity {
    @Column()
    public nickname: string;

    @Column()
    public desc: string;

    @Column({ enum: LangEnum, length: 5 })
    public language: LangEnum;

    @ManyToOne(() => UserEntity, (user) => user.translations)
    public user: UserEntity;
}

And i have problem:
UserTranslate refers to user (2 photo), but User don't have translations field that refers to UserTranslate (3 photo)

tender sleet
#

Hello, I was analyzing your entities and everything seems correct in the scenario provided. I also looked at the TypeORM documentation and there is a similar example where the column that is referencing @OneToMany does not exist in the table. But have you tried saving or fetching this record, has there been an error regarding the translations column?
https://typeorm.io/many-to-one-one-to-many-relations#

knotty loom
#

If it now showing in DB u can try add @JoinColumn decorator for the relation that u want a column to show up.

amber eagle
woven ocean