gpt4 book ai didi

node.js - Sequelize : how to add one more column to primary key formed by association?

转载 作者:行者123 更新时间:2023-12-03 22:32:01 25 4
gpt4 key购买 nike

我有3张 table
类(ID,名称)
学生(身份证,姓名)
出勤(classid,studentid,日期,现在)
我需要跟踪特定日期特定类(class)的学生出勤情况。
我必须使用 sequelize 创建模式。
现在的问题是当我写一些类似的东西
class.belongsToMany(学生,{通过:出勤})
student.belongsToMany(class,{through:attendance})
出勤表中的主键就是 (classid,studentid)。
我想包括日期列以及主键的一部分。
我怎么能做到这一点?

最佳答案

我建议在模型中创建模型出勤(classid、studentid、date、present),并在此处定义主键,如文档所述:
https://sequelize.org/master/manual/model-basics.html
只需在您想要成为主键的特定列中添加 primaryKey: true 选项。

关于node.js - Sequelize : how to add one more column to primary key formed by association?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66133208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com