My postgreSQL DB contains three Entities:
@Entity()
export class User {
constructor(email: string, displayname: string, passwordHash: string, salt: string) {
this.email = email
this.displayname = displayname;
this.passwordHash = passwordHash;
this.salt = salt;
}
@PrimaryColumn()
email!: string;
@Column()
passwordHash!: string;
@Column()
displayname!: string;
@Column()
salt!: string;
@OneToOne(type => Cafe, Cafe => Cafe.owner, {cascade: true})
cafe!: Cafe;
}
@Entity()
export class Cafe {
@PrimaryGeneratedColumn()
id!: number;
//TESTING
@Column()
name!: string;
@OneToOne(type => User, User => User.cafe)
owner!: User;
@OneToOne(type => Gamestate, Gamestate => Gamestate.cafe, { cascade: ["insert", "remove", "soft-remove", "recover"] })
gamestate!: Gamestate;
}
@Entity()
export class Gamestate {
@PrimaryGeneratedColumn()
id!: number;
@Column()
name!: string;
@OneToOne(type => Cafe, Cafe => Cafe.gamestate)
cafe!: Cafe;
public update(): void {
//TODO: do update Logic here
}
}
When creating a user with cafe and gamestate filled, they are properly cascaded into the DB. But when I try to find a Gamestate via
const foundGamestate = await connection.getRepository(Gamestate).find({ where: { cafe: { name: "Test" } }});
I get an error:
EntityColumnNotFound: No entity column "cafe" was found.
Even after trying to find a Cafe instead, the Error persists, so it seems like neither side actually has the One-To-One Relation?
const foundCafe = await connection.getRepository(Cafe).find({ where: { gamestate: { name: "Test" } }});
EntityColumnNotFound: No entity column "gamestate" was found.
Is my Entity setup wrong, or am I using find/where incorrectly?