Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This object defines the relations to other models.
static relationMappings = {
pets: {
relation: Model.HasManyRelation,
// The related model. This can be either a Model subclass constructor or an
// absolute file path to a module that exports one. We use the file path version
// here to prevent require loops.
modelClass: Animal,
join: {
from: 'persons.id',
to: 'animals.ownerId'
}
},
movies: {
relation: Model.ManyToManyRelation,
modelClass: Movie,
join: {
from: 'persons.id',
// ManyToMany relation needs the `through` object to describe the join table.
through: {
from: 'persons_movies.personId',
to: 'persons_movies.movieId'
},
to: 'movies.id'
}
},
children: {
relation: Model.HasManyRelation,
modelClass: Person,
join: {
static get relationMappings() {
// One way to prevent circular references
// is to require the model classes here.
const Person = require('./Person')
return {
actors: {
relation: Model.ManyToManyRelation,
// The related model. This can be either a Model subclass constructor or an
// absolute file path to a module that exports one.
modelClass: Person,
join: {
from: 'movies.id',
// ManyToMany relation needs the `through` object to describe the join table.
through: {
from: 'persons_movies.movieId',
to: 'persons_movies.personId'
},
to: 'persons.id'
}
}
}
static get relationMappings() {
return {
templates: {
relation: Model.ManyToManyRelation,
modelClass: Template,
join: {
from: 'page.id',
through: {
from: 'template_page.page_id',
to: 'template_page.template_id',
// modelClass: UserRole,
},
to: 'template.id',
},
},
};
}
}
static get relationMappings() {
return {
pages: {
relation: Model.ManyToManyRelation,
modelClass: Page,
join: {
from: 'template.id',
through: {
from: 'template_page.template_id',
to: 'template_page.page_id',
// modelClass: UserRole,
},
to: 'page.id',
},
},
};
}
}
static get relationMappings() {
const Review = require('./Review');
const Movie = require('./Movie');
return {
reviews: {
relation: Model.HasManyRelation,
modelClass: Review,
join: {
from: 'Person.id',
to: 'Review.reviewerId',
},
},
movies: {
relation: Model.ManyToManyRelation,
modelClass: Movie,
join: {
from: 'Person.id',
through: {
from: 'Person_Movie.personId',
to: 'Person_Movie.movieId',
},
to: 'Movie.id',
},
},
parent: {
relation: Model.BelongsToOneRelation,
modelClass: Person,
join: {
from: 'Person.parentId',
static get relationMappings() {
return {
roles: {
relation: Model.ManyToManyRelation,
modelClass: Role,
join: {
from: 'user.id',
through: {
from: 'user_role.user_id',
to: 'user_role.role_id',
},
to: 'role.id',
},
},
posts: {
relation: Model.HasManyRelation,
modelClass: Post,
join: {
from: 'user.id',
to: 'post.user_id',
},
},
tags: {
relation: Model.ManyToManyRelation,
modelClass: Tag,
join: {
from: 'post.id',
through: {
from: 'post_tag.post_id',
to: 'post_tag.tag_id',
},
to: 'tag.id',
},
},
attachments: {
relation: Model.ManyToManyRelation,
modelClass: Attachment,
join: {
from: 'post.id',
through: {
from: 'post_attachment.post_id',
to: 'post_attachment.attachment_id',
},
to: 'attachment.id',
},
},
comments: {
relation: Model.ManyToManyRelation,
modelClass: Comment,
join: {
from: 'post.id',
through: {
properties: {
id: { type: 'integer' },
email: { type: 'string', format: 'email' },
name: { type: 'string', minLength: 1, maxLength: 255 },
password: { type: 'string' },
verified: { type: 'boolean' },
verificationToken: { type: 'string' },
passwordResetToken: { type: 'string' },
tokensRevokedAt: { type: 'string', format: 'date-time' },
roleNames: { type: 'array' },
},
}
public static relationMappings = {
roles: {
relation: Model.ManyToManyRelation,
modelClass: __dirname + '/role',
join: {
from: 'users.id',
through: {
from: 'roles_roleable.user_id',
to: 'roles_roleable.role_id',
},
to: 'roles.id',
},
},
}
public $afterGet(): void {
if (this.roles) {
this.roleNames = this.roles.map((role): string => { return role.name })
}
static get relationMappings(): RelationMappings {
return {
project: {
relation: Model.BelongsToOneRelation,
modelClass: `${__dirname}/Project`,
join: {
from: 'mediaTag.projectId',
to: 'project.id'
}
},
media: {
relation: Model.ManyToManyRelation,
modelClass: `${__dirname}/Media`,
join: {
from: 'mediaTag.id',
through: {
from: 'media_mediaTag.mediaTagId',
to: 'media_mediaTag.mediaId'
},
to: 'media.id'
}
}
};
}
static get relationMappings() {
return {
role: {
relation: Model.ManyToManyRelation,
modelClass: User,
join: {
from: 'role.id',
through: {
from: 'user_role.role_id',
to: 'user_role.user_id',
},
to: 'user.id',
},
},
};
}
}