-
Notifications
You must be signed in to change notification settings - Fork 192
Description
I'm new to this project (and sequelize and postgres) so this may be a dumb question, but I'm having trouble doing my model associations in the model file itself. If I do something like (this is an example, not sure it would happen under this circumstance) -
`
const Sequelize = require('sequelize');
const sequelize = require('../../../../config/database');
const User = require('../users/User');
const DataTypes = Sequelize.DataTypes;
const Manager = sequelize.define('Manager', {
license_num: DataTypes.STRING,
reputation: DataTypes.FLOAT,
});
Manager.belongsTo(User);
module.exports = Manager;
`
I get an error to the effect that Manager.belongsTo is being called with something that is not a subclass of Model. If I log it out, I get User = {}. It seems to have an issue with the load order possibly? ie The sequelize connection has not established that the User is not a sequelize object.
If I do a function that holds all my associations in a separate file and run them in api.js, it works fine, but it seems cleaner to do them in the model file itself. Any ideas?