关于 sequelizejs 的 2 个问题

2014-04-04 17:31:44 +08:00
 ryanking8215
## 不能有Model的column
sequelize.define()里不能有'Model'的column,会报:

TypeError: Cannot read property 'Model' of undefined

## 1:N关系时创建出来的foreign key的类型不对,会固定是int(11)类型的
例如
var Class = Sequelize.define('class', {
no: {type:Sequelize.STRING,primaryKey:true},
})

var Student = Sequelize.define('student',{
no: Sequelize.INTEGER,
name: Sequelize.STRING,
})

定义关系:
Class.hasMany(Student, {foreignKey: 'class'})
Student.belongsTo(Class, {foreignKey: 'class'})

应该会在student的表上建立class的column,类型应该和Class.no的类型一致,但是它一直固定为
int(11),貌似是有问题的。

mysql> desc student;

+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| no | int(11) | NO | PRI | NULL | |
| name | varchar(255) | YES | | NULL | |
| sex | enum('f','m') | YES | | NULL | |
| class | int(11) | YES | | NULL | |
+-------+---------------+------+-----+---------+-------+


大家有碰到过吗?
3464 次点击
所在节点    Node.js
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/107282

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX