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
{ | |
"development": { | |
"username": "root", | |
"password": "My_mysql_root_p@ssw0rd", | |
"database": "nodejs_relationship_demo", | |
"host": "127.0.0.1", | |
"dialect": "mysql" | |
}, | |
"test": { | |
"username": "root", |
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
'use strict'; | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.createTable('Companies', { | |
id: { | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
type: Sequelize.INTEGER | |
}, |
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
'use strict'; | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.createTable('Companies', { | |
id: { | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
type: Sequelize.INTEGER | |
}, |
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
'use strict'; | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.createTable('Companies', { | |
id: { | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
type: Sequelize.INTEGER | |
}, |
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
'use strict'; | |
module.exports = (sequelize, DataTypes) => { | |
const User = sequelize.define('User', { | |
email: DataTypes.STRING, | |
firstName: DataTypes.STRING, | |
lastName: DataTypes.STRING, | |
companyId: DataTypes.INTEGER | |
}, {}); | |
User.associate = function(models) { | |
User.belongsTo(models.Company, {foreignKey: 'companyId', as: 'company'}) |
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
'use strict'; | |
module.exports = (sequelize, DataTypes) => { | |
const Company = sequelize.define('Company', { | |
name: DataTypes.STRING | |
}, {}); | |
Company.associate = function(models) { | |
Company.hasMany(models.User, {as: 'employes'}) | |
}; | |
return Company; | |
}; |
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
'use strict'; | |
module.exports = (sequelize, DataTypes) => { | |
const User = sequelize.define('User', { | |
email: DataTypes.STRING, | |
firstName: DataTypes.STRING, | |
lastName: DataTypes.STRING, | |
companyId: DataTypes.INTEGER | |
}, {}); | |
User.associate = function(models) { | |
User.belongsTo(models.Company, {foreignKey: 'companyId', as: 'company'}) |
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
const models = require('./models'); | |
const User = models.User; | |
const Company = models.Company; | |
const WorkingDay = models.WorkingDay; |
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
const models = require('./models'); | |
const User = models.User; | |
const Company = models.Company; | |
const WorkingDay = models.WorkingDay; | |
Company.create({ | |
name: "My super company" | |
}) | |
.then((newCompany) => { | |
// The get() function allows you to recover only the DataValues of the object |
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
const models = require('./models'); | |
const User = models.User; | |
const Company = models.Company; | |
const WorkingDay = models.WorkingDay; | |
User.bulkCreate([ | |
{email: '[email protected]', firstName: 'John', lastName: 'DOE', companyId: 1}, | |
{email: '[email protected]', firstName: 'Logan', lastName: 'WOLVERINE', companyId: 1}, | |
{email: '[email protected]', firstName: 'John', lastName: 'CONNOR', companyId: 1} | |
]) |
OlderNewer