Files
mattermost-mobile/app/database/server/models/groups_in_channel.ts
Avinash Lingaloo 237a6e7932 MM_30476 [v2] Section 'Group' of the server schema (#5072)
* MM_30476 : Added all isolated tables from the server schema

* MM_30476 : Updated 'test' script in package.json

* MM_30476 : ADDED team section of the server schema

* MM_30476 : ADDED section for Group from the server schema

* MM_30476 : One PR for one section only

* MM_30476 : One PR for one section only

* MM_30476 : Apply suggestions from code review

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* MM_30476 : ADDED lazy queries to group_membership model

* MM_30476 : Update model to match definition - GroupsInChannel

* MM_30476 : Updated all comments to match their variable/field name

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-01-14 00:26:55 +04:00

49 lines
1.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Relation} from '@nozbe/watermelondb';
import Model, {Associations} from '@nozbe/watermelondb/Model';
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
import {MM_TABLES} from '@constants/database';
import Channel from '@typings/database/channel';
import Group from '@typings/database/group';
const {GROUP, GROUPS_IN_CHANNEL, CHANNEL} = MM_TABLES.SERVER;
/**
* The GroupsInChannel links the Channel model with the Group model
*/
export default class GroupsInChannel extends Model {
/** table (entity name) : GroupsInChannel */
static table = GROUPS_IN_CHANNEL;
/** associations : Describes every relationship to this entity. */
static associations: Associations = {
/** A GROUP can be associated with multiple GROUPS_IN_CHANNEL (relationship is 1:N) */
[GROUP]: {type: 'belongs_to', key: 'group_id'},
/** A CHANNEL can be associated with multiple GROUPS_IN_CHANNEL (relationship is 1:N) */
[CHANNEL]: {type: 'belongs_to', key: 'channel_id'},
};
/** channel_id : The foreign key of the related CHANNEL model */
@field('channel_id') channelId!: string;
/** group_id : The foreign key of the related GROUP model */
@field('group_id') groupId!: string;
/** member_count : The number of members in that group */
@field('member_count') memberCount!: number;
/** timezone_count : The number of timezones in that group */
@field('timezone_count') timezoneCount!: number;
/** channel : The related record to the parent Channel model */
@immutableRelation(CHANNEL, 'channel_id') channel!: Relation<Channel>;
/** group : The related record to the parent Group model */
@immutableRelation(GROUP, 'group_id') group!: Relation<Group>;
}