1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 04:32:35 +01:00

typeorm inverse relations of guild relations

This commit is contained in:
Madeline 2023-09-02 02:21:42 +10:00
parent 27bcef502c
commit 2f48212e6e
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
7 changed files with 12 additions and 10 deletions

View File

@ -97,10 +97,11 @@ export class Channel extends BaseClass {
guild_id?: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, {
@ManyToOne(() => Guild, (guild) => guild.channels, {
onDelete: "CASCADE",
nullable: true,
})
guild: Guild;
guild?: Guild;
@Column({ nullable: true })
@RelationId((channel: Channel) => channel.parent)

View File

@ -33,7 +33,7 @@ export class Emoji extends BaseClass {
guild_id: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, {
@ManyToOne(() => Guild, (guild) => guild.emojis, {
onDelete: "CASCADE",
})
guild: Guild;

View File

@ -53,7 +53,7 @@ export class Invite extends BaseClassWithoutId {
guild_id: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, {
@ManyToOne(() => Guild, (guild) => guild.invites, {
onDelete: "CASCADE",
})
guild: Guild;

View File

@ -327,6 +327,7 @@ export class Member extends BaseClassWithoutId {
id: guild_id,
},
relations: PublicGuildRelations,
relationLoadStrategy: "query",
});
const memberCount = await Member.count({ where: { guild_id } });

View File

@ -23,12 +23,12 @@ import { Guild } from "./Guild";
@Entity("roles")
export class Role extends BaseClass {
@Column({ nullable: true })
@Column()
@RelationId((role: Role) => role.guild)
guild_id: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, {
@ManyToOne(() => Guild, (guild) => guild.roles, {
onDelete: "CASCADE",
})
guild: Guild;

View File

@ -17,9 +17,9 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { User } from "./User";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
export enum StickerType {
STANDARD = 1,
@ -62,7 +62,7 @@ export class Sticker extends BaseClass {
guild_id?: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, {
@ManyToOne(() => Guild, (guild) => guild.stickers, {
onDelete: "CASCADE",
})
guild?: Guild;

View File

@ -20,8 +20,8 @@ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { User } from "./User";
import { Member } from "./Member";
import { User } from "./User";
//https://gist.github.com/vassjozsef/e482c65df6ee1facaace8b3c9ff66145#file-voice_state-ex
@Entity("voice_states")
@ -31,7 +31,7 @@ export class VoiceState extends BaseClass {
guild_id: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, {
@ManyToOne(() => Guild, (guild) => guild.voice_states, {
onDelete: "CASCADE",
})
guild?: Guild;