| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- const Schwifty = require('@hapipal/schwifty')
- const Joi = require('joi')
- const TagAssociation = require('./tag-association')
- const Response = require('./response')
- const User = require('./user')
-
- module.exports = class Profile extends Schwifty.Model {
- static get tableName() {
- return 'profiles'
- }
- static get relationMappings() {
- return {
- tags: {
- relation: Schwifty.Model.HasManyRelation,
- modelClass: TagAssociation,
- join: {
- from: 'tag_associations.profile_id',
- to: 'profiles.profile_id',
- },
- },
- responses: {
- relation: Schwifty.Model.HasManyRelation,
- modelClass: Response,
- join: {
- from: 'responses.profile_id',
- to: 'profiles.profile_id',
- },
- },
- user: {
- relation: Schwifty.Model.BelongsToOneRelation,
- modelClass: User,
- join: {
- from: 'users.user_id',
- to: 'profiles.user_id',
- },
- },
- }
- }
- static get joiSchema() {
- return Joi.object({
- profile_id: Joi.number(),
- user_id: Joi.number(),
- })
- }
- }
|