Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions models/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (sequelize, DataTypes) {
const Team = sequelize.define('Team', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
AllowNull: false
},
name: DataTypes.STRING,
description: DataTypes.STRING,
timestamps: true,
});
return Team;
}
33 changes: 33 additions & 0 deletions models/teamMember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const Team = require('./team')
const User = require('./user')

module.exports = function (sequelize, DataTypes) {
const TeamMember = sequelize.define('TeamMember', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
AllowNull: false
},
team_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Team',
key: 'id',
},
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'User',
key: 'id',
},
},
timestamps: true,
})
TeamMember.belongsTo(Team, { foreignKey: 'team_id' });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the build is still failing because you are using TeamMember.belongsTo in a wrong way you need to do it like this,
TeamMember.associate = (models) => { TeamMember.belongsTo(models.Team, { foreignKey: 'team_id'}) }
something like this, in your current implementation it could be possible that Team that you are importing is a empty object ... also remove the imports at the top they are not needed anymore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reference you can have a look at this file
here

TeamMember.belongsTo(User, { foreignKey: 'user_id' });

return TeamMember;
}