You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

grouping.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const Schwifty = require('@hapipal/schwifty')
  2. const groupingSchema = require('../schemas/groupings')
  3. const Profile = require('./profile')
  4. const Tag = require('./tag')
  5. module.exports = class Grouping extends Schwifty.Model {
  6. static get tableName() {
  7. return 'groupings'
  8. }
  9. static get relationMappings() {
  10. return {
  11. profiles: {
  12. relation: Schwifty.Model.ManyToManyRelation,
  13. modelClass: Profile,
  14. join: {
  15. from: 'groupings.grouping_id',
  16. through: {
  17. from: 'memberships.grouping_id',
  18. to: 'memberships.profile_id',
  19. },
  20. to: 'profiles.profile_id',
  21. },
  22. },
  23. tags: {
  24. relation: Schwifty.Model.HasManyRelation,
  25. modelClass: Tag,
  26. join: {
  27. from: 'groupings.grouping_id',
  28. through: {
  29. from: 'tag_associations.grouping_id',
  30. to: 'tag_associations.tag_id',
  31. },
  32. to: 'tags.tag_id',
  33. },
  34. },
  35. }
  36. }
  37. static get joiSchema() {
  38. return groupingSchema.single
  39. }
  40. }