Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- module.exports = function(sequelize, DataTypes) {
- //Define the user table, and its columns, data types, attributes
- var User = sequelize.define('User', {
- user_id: {...},
- user_name: {...}
- },
- {
- //Define the constraints, such as foreign key
- classMethods:{
- associate: function(models) {
- User.belongsToMany(models.Group);
- User.hasMany(models.Old_Password);
- }
- }
- });
- return User;
- };
- 'use strict';
- module.exports = function(sequelize, DataTypes){
- var Role = sequelize.define('Role',{
- role_id: {...},
- role_name:{...}
- },
- {
- //Define the constraints, such as foreign key
- classMethods:{
- associate: function(models){
- Role.belongsTo(models.User);
- }
- }
- });
- return Role;
- };
- 'use strict';
- module.exports = function(sequelize, DataTypes){
- var Group = sequelize.define('group', {
- group_id: {...},
- group_name: {...},
- });
- return Group;
- };
- 'use strict';
- module.exports = function(sequelize, DataTypes){
- //Define the table, and its columns, data types, attributes
- var Old_Password = sequelize.define('Old_Password', {
- old_password_id: {...},
- old_password_value: {...}
- },
- {
- //Define the constraints, such as foreign key
- classMethods:{
- associate: function(models){
- Old_Password.hasOne(models.User);
- }
- }
- });
- return Old_Password;
- };
- classMethods:{
- associate: function(models){
- User.belongsToMany(models.Group, {
- // Define the join table
- through: 'user_group',
- // Define the foreign key
- foreignKey: 'group_id'
- });
- models.Group.belongsToMany(User, {
- through: 'user_group',
- foreignKey: 'user_id'
- });
- User.hasMany(models.Old_Password);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement