models.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. This file is for configuring the model relations. For example, users can have many
  3. notes and notes belong to a user. This module can also be required in other modules to
  4. avoid always need sequelize as well to import the models
  5. */
  6. var Sequelize = require('sequelize');
  7. // We're using sqlite for this demo app, so the username and password don't really
  8. // matter, anything works. Other databases such as postgresql could be used here instead.
  9. // see: http://sequelizejs.com/docs/1.7.8/usage#basics
  10. // for more information on how this can be configured.
  11. var sequelize = new Sequelize('note_wrangler', 'username', 'password', {
  12. dialect: "sqlite",
  13. port: 3306,
  14. storage: './database.sqlite' // Local to where app.js is running from
  15. });
  16. var User = sequelize.import(__dirname + "/models/user");
  17. var Note = sequelize.import(__dirname + "/models/note");
  18. var Category = sequelize.import(__dirname + "/models/category");
  19. // Set user/note associations
  20. User.hasMany(Note);
  21. Note.belongsTo(User);
  22. // Set note/note type associations
  23. Category.hasMany(Note);
  24. Note.belongsTo(Category);
  25. module.exports = {
  26. User: User,
  27. Note: Note,
  28. Category: Category,
  29. sequelize: sequelize
  30. }