Last active
June 14, 2019 00:25
-
-
Save pillows/b4507c40279e923baec1b365f4c40640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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