So I have two tables, one with a list of users, then another with associated accounts. So for example, one user might have two accounts. Also, several users might be associated with overlapping accounts.
I have a belongsTo and a hasMany, as I've done in the past.
but when I try to get the associated accounts, I'm getting back an error stating Accounts.id is not found.
Association:
Accounts.belongsTo(Users,{foreignKey: 'uid'})
Users.hasMany(Accounts, {foreignKey: 'uid'})
uid is a primaryKey on the User table. There are no primary keys on the Accounts table.
Models:
Users
db.define('users', {
uid: {
type: Sequelize.BIGINT,
primaryKey: true
},
login_count: {
type: Sequelize.INTEGER,
defaultValue: 0
},
approved: {
type: Sequelize.BOOLEAN,
defaultValue: false
},
last_login_ip: {
type: Sequelize.INET,
}
});
Accounts:
db.define('accounts', {
uid: {
type: Sequelize.BIGINT
},
account_num: {
type: Sequelize.BIGINT
},
token: {
type: Sequelize.STRING
}
});