Files
mattermost-mobile/app/database/models/server/group_channel.ts
Shaz MJ 6d6085ed4b [Gekidou] Groups + group membership schema (#6251)
* First pass at adding groups to mobile

* Reverts back and updates the group vars

* Cleans tests

* Missing created/updated/deleted fields in types, many-many ref fix

* Adds to manager

* PR Feedback

* Failing test

* Move FK out of comment, add indexes

* updated docs/database/server artefacts

Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>
2022-05-19 17:54:39 +10:00

55 lines
2.0 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Relation} from '@nozbe/watermelondb';
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
import Model, {Associations} from '@nozbe/watermelondb/Model';
import {MM_TABLES} from '@constants/database';
import type ChannelModel from '@typings/database/models/servers/channel';
import type GroupModel from '@typings/database/models/servers/group';
import type GroupChannelInterface from '@typings/database/models/servers/group_channel';
const {CHANNEL, GROUP, GROUP_CHANNEL} = MM_TABLES.SERVER;
/**
* The GroupChannel model represents the 'association table' where many groups have channels and many channels are in
* groups (relationship type N:N)
*/
export default class GroupChannelModel extends Model implements GroupChannelInterface {
/** table (name) : GroupChannel */
static table = GROUP_CHANNEL;
/** associations : Describes every relationship to this table. */
static associations: Associations = {
/** A GroupChannel belongs to a Group */
[GROUP]: {type: 'belongs_to', key: 'group_id'},
/** A GroupChannel has a Channel */
[CHANNEL]: {type: 'belongs_to', key: 'channel_id'},
};
/** group_id : The foreign key to the related Group record */
@field('group_id') groupId!: string;
/** channel_id : The foreign key to the related Channel record */
@field('channel_id') channelId!: string;
/** created_at : The creation date for this row */
@field('created_at') createdAt!: number;
/** updated_at : The update date for this row */
@field('updated_at') updatedAt!: number;
/** deleted_at : The delete date for this row */
@field('deleted_at') deletedAt!: number;
/** group : The related group */
@immutableRelation(GROUP, 'group_id') group!: Relation<GroupModel>;
/** channel : The related channel */
@immutableRelation(CHANNEL, 'channel_id') channel!: Relation<ChannelModel>;
}