Skip to content

Instantly share code, notes, and snippets.

@pillows
Last active June 14, 2019 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pillows/b4507c40279e923baec1b365f4c40640 to your computer and use it in GitHub Desktop.
Save pillows/b4507c40279e923baec1b365f4c40640 to your computer and use it in GitHub Desktop.
class Campus extends Sequelize.Model {}
Campus.init({
name:{
type:Sequelize.STRING,
allowNull: false,
notEmpty: true
},
imageUrl:{
type:Sequelize.STRING,
defaultValue: "https://hunter.cuny.edu",
},
address:{
type:Sequelize.STRING,
allowNull: false,
notEmpty: true
},
description:{
type:Sequelize.STRING,
args:[0,500]
},
},{
sequelize,
modelName:"campus"
})
Campus.associate = (models) => {
Campus.hasMany(models.Students, {foreignKey: 'studentId'})
}
class Students extends Sequelize.Model {}
Students.init({
firstName:{
type:Sequelize.STRING,
allowNull: false,
notEmpty: true
},
lastName:{
type:Sequelize.STRING,
allowNull: false,
notEmpty: true
},
email:{
type:Sequelize.STRING,
allowNull: false,
notEmpty: true,
isEmail: true
},
imageUrl:{
type:Sequelize.STRING,
defaultValue: "https://hunter.cuny.edu",
},
gpa:{
type:Sequelize.DOUBLE,
len: [0.0,4.0]
},
belongsTo:{
type:Sequelize.STRING,
notEmpty: true
}
},{
sequelize,
modelName:"students"
});
Students.associate = (models) => {
Students.belongsTo(models.Campus, {foreignKey: 'campusId'})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment