Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. 'use strict';
  2. module.exports = function(sequelize, DataTypes) {
  3. var Tweet = sequelize.define('Tweet', {
  4. tweet: DataTypes.TEXT
  5. }, {
  6. classMethods: {
  7. associate: function(models) {
  8. // associations can be defined here
  9. //creating a one-to-many relationship from user->tweets
  10. models.User.hasMany(models.Tweet, {as: 'tweets'});
  11. }
  12. }
  13. });
  14. return Tweet;
  15. };
  16.  
  17. 'use strict';
  18. module.exports = function (sequelize, DataTypes) {
  19. var User = sequelize.define('User', {
  20. username: DataTypes.STRING,
  21. password: DataTypes.STRING
  22. }, {
  23. //classMethod guarantees the password provided by the user matches what's in the db
  24. classMethods: {
  25. associate: function (models) {
  26. //associate every tweet to having one author
  27. models.Tweet.hasOne(models.User, { as: "Author" });
  28. models.Tweet#setAuthor(anAuthor);
  29. }
  30. }
  31. });
  32. return User;
  33. }; //**Note that 'models' contains two objects: 'Tweet' and 'User'**
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement