Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. 'use strict';
  2.  
  3. module.exports = function(sequelize, DataTypes) {
  4.  
  5. //Define the user table, and its columns, data types, attributes
  6. var User = sequelize.define('User', {
  7. user_id: {...},
  8. user_name: {...}
  9. },
  10. {
  11. //Define the constraints, such as foreign key
  12. classMethods:{
  13. associate: function(models) {
  14. User.belongsToMany(models.Group);
  15. User.hasMany(models.Old_Password);
  16. }
  17. }
  18. });
  19.  
  20. return User;
  21. };
  22.  
  23. 'use strict';
  24.  
  25. module.exports = function(sequelize, DataTypes){
  26.  
  27. var Role = sequelize.define('Role',{
  28. role_id: {...},
  29. role_name:{...}
  30. },
  31. {
  32. //Define the constraints, such as foreign key
  33. classMethods:{
  34. associate: function(models){
  35. Role.belongsTo(models.User);
  36. }
  37. }
  38. });
  39.  
  40. return Role;
  41. };
  42.  
  43. 'use strict';
  44.  
  45. module.exports = function(sequelize, DataTypes){
  46.  
  47. var Group = sequelize.define('group', {
  48. group_id: {...},
  49. group_name: {...},
  50. });
  51.  
  52. return Group;
  53. };
  54.  
  55. 'use strict';
  56.  
  57. module.exports = function(sequelize, DataTypes){
  58.  
  59. //Define the table, and its columns, data types, attributes
  60. var Old_Password = sequelize.define('Old_Password', {
  61. old_password_id: {...},
  62. old_password_value: {...}
  63. },
  64. {
  65. //Define the constraints, such as foreign key
  66. classMethods:{
  67. associate: function(models){
  68. Old_Password.hasOne(models.User);
  69. }
  70. }
  71. });
  72.  
  73. return Old_Password;
  74. };
  75.  
  76. classMethods:{
  77. associate: function(models){
  78. User.belongsToMany(models.Group, {
  79. // Define the join table
  80. through: 'user_group',
  81. // Define the foreign key
  82. foreignKey: 'group_id'
  83. });
  84. models.Group.belongsToMany(User, {
  85. through: 'user_group',
  86. foreignKey: 'user_id'
  87. });
  88. User.hasMany(models.Old_Password);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement