From 13e794a9197f1d301e2dc7b3ca2e086fb93db8b0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Jul 2024 06:18:09 +0200 Subject: [PATCH] Add associations to all database models --- src/database/models.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/database/models.rs b/src/database/models.rs index 6803b6cf..8f317d2b 100644 --- a/src/database/models.rs +++ b/src/database/models.rs @@ -1,9 +1,9 @@ -use diesel::{Identifiable, Insertable, Queryable, Selectable}; +use diesel::{Identifiable, Insertable, Queryable, Selectable, Associations}; use diesel::pg::Pg; use super::schema::{users, telegram, discord, steam}; -#[derive(Debug, Clone, Identifiable, Queryable, Selectable, Insertable)] +#[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable)] #[diesel(table_name = users)] #[diesel(check_for_backend(Pg))] pub struct RoyalnetUser { @@ -12,7 +12,8 @@ pub struct RoyalnetUser { } -#[derive(Debug, Clone, Identifiable, Queryable, Selectable, Insertable)] +#[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable, Associations)] +#[diesel(belongs_to(RoyalnetUser, foreign_key = user_id))] #[diesel(table_name = telegram)] #[diesel(primary_key(telegram_id))] #[diesel(check_for_backend(Pg))] @@ -22,7 +23,8 @@ pub struct TelegramUser { } -#[derive(Debug, Clone, Identifiable, Queryable, Selectable, Insertable)] +#[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable, Associations)] +#[diesel(belongs_to(RoyalnetUser, foreign_key = user_id))] #[diesel(table_name = discord)] #[diesel(primary_key(discord_id))] #[diesel(check_for_backend(Pg))] @@ -32,7 +34,8 @@ pub struct DiscordUser { } -#[derive(Debug, Clone, Identifiable, Queryable, Selectable, Insertable)] +#[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable, Associations)] +#[diesel(belongs_to(RoyalnetUser, foreign_key = user_id))] #[diesel(table_name = steam)] #[diesel(primary_key(steam_id))] #[diesel(check_for_backend(Pg))]