thread.js 900 B

123456789101112131415161718192021222324252627282930313233343536
  1. module.exports = (sequelize, DataTypes) => {
  2. let Thread = sequelize.define('Thread', {
  3. name: DataTypes.STRING
  4. }, {
  5. classMethods: {
  6. associate (models) {
  7. Thread.belongsTo(models.User)
  8. Thread.belongsTo(models.Category)
  9. Thread.hasMany(models.Post)
  10. },
  11. includeOptions () {
  12. let models = sequelize.models
  13. return [
  14. { model: models.User, attributes: ['username', 'createdAt', 'updatedAt', 'id'] },
  15. models.Category,
  16. {
  17. model: models.Post,
  18. include: [
  19. { model: models.User, attributes: ['username', 'createdAt', 'id'] },
  20. {
  21. model: models.Post, as: 'ReplyingTo', include:
  22. [{ model: models.User, attributes: ['username', 'id'] }]
  23. }, {
  24. model: models.Post, as: 'Replies', include:
  25. [{ model: models.User, attributes: ['username', 'id'] }]
  26. }
  27. ]
  28. }
  29. ]
  30. }
  31. }
  32. })
  33. return Thread
  34. }