V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ryanking8215
V2EX  ›  Node.js

关于 sequelizejs 的 2 个问题

  •  
  •   ryanking8215 · 2014-04-04 17:31:44 +08:00 · 3458 次点击
    这是一个创建于 3674 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ## 不能有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 | |
    +-------+---------------+------+-----+---------+-------+


    大家有碰到过吗?
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3364 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:58 · PVG 19:58 · LAX 04:58 · JFK 07:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.