summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-02 02:21:42 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-02 02:21:42 +1000
commit2f48212e6e6813f90eb13cf8ed79e0ebb3440b31 (patch)
tree792587a7f3dee4ef09973b21460e12d238d9b792
parentMerge branch 'master' of github.com:spacebarchat/server (diff)
downloadserver-2f48212e6e6813f90eb13cf8ed79e0ebb3440b31.tar.xz
typeorm inverse relations of guild relations
-rw-r--r--src/util/entities/Channel.ts5
-rw-r--r--src/util/entities/Emoji.ts2
-rw-r--r--src/util/entities/Invite.ts2
-rw-r--r--src/util/entities/Member.ts1
-rw-r--r--src/util/entities/Role.ts4
-rw-r--r--src/util/entities/Sticker.ts4
-rw-r--r--src/util/entities/VoiceState.ts4
7 files changed, 12 insertions, 10 deletions
diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 6268d735..9f7041d4 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -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)
diff --git a/src/util/entities/Emoji.ts b/src/util/entities/Emoji.ts
index 0bc2f423..4d851698 100644
--- a/src/util/entities/Emoji.ts
+++ b/src/util/entities/Emoji.ts
@@ -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;
diff --git a/src/util/entities/Invite.ts b/src/util/entities/Invite.ts
index 7970c4f0..f7e54fbe 100644
--- a/src/util/entities/Invite.ts
+++ b/src/util/entities/Invite.ts
@@ -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;
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index d305e4f5..0535313e 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -327,6 +327,7 @@ export class Member extends BaseClassWithoutId {
 				id: guild_id,
 			},
 			relations: PublicGuildRelations,
+			relationLoadStrategy: "query",
 		});
 
 		const memberCount = await Member.count({ where: { guild_id } });
diff --git a/src/util/entities/Role.ts b/src/util/entities/Role.ts
index 9a601f31..e8e5feda 100644
--- a/src/util/entities/Role.ts
+++ b/src/util/entities/Role.ts
@@ -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;
diff --git a/src/util/entities/Sticker.ts b/src/util/entities/Sticker.ts
index cd07e65a..e9294f92 100644
--- a/src/util/entities/Sticker.ts
+++ b/src/util/entities/Sticker.ts
@@ -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;
diff --git a/src/util/entities/VoiceState.ts b/src/util/entities/VoiceState.ts
index b291c4d3..84b0ca71 100644
--- a/src/util/entities/VoiceState.ts
+++ b/src/util/entities/VoiceState.ts
@@ -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;