Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

egg里怎么完美使用sequelize

$
0
0

感觉model层写的很混乱,求一个example

module.exports = app => {
  const { DATE, INTEGER, STRING } = app.Sequelize;

  return app.model.define('Post', {
    title: STRING,
    user_id: INTEGER,
    created_at: DATE,
    updated_at: DATE,
  }, {
    classMethods: {
      associate() {
        app.model.Post.belongsTo(app.model.User, { as: 'user' });
      },
    },
  });
};

这种写法,真是写不下去 能否有办法变成类似于这样

Class Post extends Sequelize {
		static ...
}

Viewing all articles
Browse latest Browse all 14821

Trending Articles