【发布时间】:2021-05-13 20:25:39
【问题描述】:
我正在使用 Nest Js 和 TypeOrm 构建应用程序。我在 ShoppingList 和 Item 之间有多对多的关系,如下所示:
购物清单
@Entity()
export class ShoppingList {
@PrimaryGeneratedColumn('uuid')
id: number;
@Column()
name: string;
@CreateDateColumn({ name: 'created_At' })
createdAt: Date;
@Column({ default: 'open' })
status: 'completed' | 'cancelled' | 'open';
@ManyToOne(() => User, (User) => User.shopping_lists)
owner: User;
@OneToMany(
() => ShoppingListItem,
(shoppingListItem) => shoppingListItem.shoppingList,
)
items: ShoppingListItem[];
}
购物清单项目:
@Entity()
export class ShoppingListItem {
@Column()
quantity: number;
@Column()
checked: boolean;
@ManyToOne(() => Item, (item) => item.lists, { primary: true })
item: Item;
@ManyToOne(() => ShoppingList, (shoppingList) => shoppingList.items, {
primary: true,
})
shoppingList: ShoppingList;
}
项目:
@Entity()
export class Item {
@PrimaryGeneratedColumn('uuid')
id: number;
@Column({ unique: true })
name: string;
@OneToMany(
() => ShoppingListItem,
(shoppingListItem: ShoppingListItem) => shoppingListItem.item,
)
lists: ShoppingListItem[];
@ManyToOne(() => Category, (category) => category.items)
category: Category;
}
我的意思是:如何更新多对多关系中的“已检查”自定义属性??
【问题讨论】:
标签: javascript nestjs typeorm