NestJS TypeORM OneToMany 列未显示在数据库中
NestJS TypeORM OneToMany column not displayed in db
我在table“电影”和“喜欢”之间设置了一对多关系。 table“喜欢”和“电影”之间的多对一关系。在类似的 table 中,我可以看到创建了一个列 'movieID',该列按预期将行链接到电影。但是,电影 table 中没有创建应该表明关系的“喜欢”列。
import { Like } from './like.entity';
@Entity()
export class Movie {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@OneToMany(() => Like, (like) => like.movie)
likes: Like[];
}
import { Movie } from './movie.entity';
@Entity()
export class Like {
@PrimaryGeneratedColumn()
id: number;
@Column({ default: 0 })
likes: number;
@ManyToOne(() => Movie, (movie) => movie.likes)
movie: Movie;
}
OneToMany
/ManyToOne
关系只需要 table 中的条目表示 Many
部分。知道哪些喜欢属于一部电影就足以推断出一部电影有哪些喜欢。在两个 table 中维护信息将是低效且容易出错的。该行为符合 ORM 的预期。
我在table“电影”和“喜欢”之间设置了一对多关系。 table“喜欢”和“电影”之间的多对一关系。在类似的 table 中,我可以看到创建了一个列 'movieID',该列按预期将行链接到电影。但是,电影 table 中没有创建应该表明关系的“喜欢”列。
import { Like } from './like.entity';
@Entity()
export class Movie {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@OneToMany(() => Like, (like) => like.movie)
likes: Like[];
}
import { Movie } from './movie.entity';
@Entity()
export class Like {
@PrimaryGeneratedColumn()
id: number;
@Column({ default: 0 })
likes: number;
@ManyToOne(() => Movie, (movie) => movie.likes)
movie: Movie;
}
OneToMany
/ManyToOne
关系只需要 table 中的条目表示 Many
部分。知道哪些喜欢属于一部电影就足以推断出一部电影有哪些喜欢。在两个 table 中维护信息将是低效且容易出错的。该行为符合 ORM 的预期。