Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you correctly access the defined models from a sequelize instance?

I've seen this syntax to access a defined model from the Sequelize instance:

var sequelize = new Sequelize('database', 'username'[, 'password']);

var Project = sequelize.define('Project', {
  title: Sequelize.STRING,
  description: Sequelize.TEXT
});

sequelize.Project.build({});

However, when I tried it myself on 1.7.0:

console.log(sequelize.Project);

Returned undefined

Is there another way or a correct way to accomplish this?

like image 905
Noah Goodrich Avatar asked Sep 30 '22 22:09

Noah Goodrich


1 Answers

You need to attach the object on your own. Usually people do something like:

sequelize.Project = sequelize.import('./models/project');

Sequelize doesn't do that for you. (The fact that people decide to attach models to the sequelize object is purely a convenience thing that emerged)

Source: Github Issues #1693

like image 59
Noah Goodrich Avatar answered Oct 03 '22 12:10

Noah Goodrich