V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ryanking8215
V2EX  ›  Node.js

关于 sequelizejs 的 2 个问题

  •  
  •   ryanking8215 · Apr 4, 2014 · 4217 views
    This topic created in 4418 days ago, the information mentioned may be changed or developed.
    ## 不能有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 | |
    +-------+---------------+------+-----+---------+-------+


    大家有碰到过吗?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2940 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 06:25 · PVG 14:25 · LAX 23:25 · JFK 02:25
    ♥ Do have faith in what you're doing.