From f0cdd4bd7ad5f534e7be02c8c4dec9eec8a87a32 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 30 Apr 2024 00:53:57 +0200 Subject: [PATCH] feat: like and share relations with object --- src/model/like.rs | 15 ++++++++++++++- src/model/object.rs | 18 ++++++++++++++++++ src/model/share.rs | 15 ++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/model/like.rs b/src/model/like.rs index 2922857d..2e072f6b 100644 --- a/src/model/like.rs +++ b/src/model/like.rs @@ -11,6 +11,19 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm( + belongs_to = "super::object::Entity", + from = "Column::Likes", + to = "super::object::Column::Id", + )] + Object +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Object.def() + } +} impl ActiveModelBehavior for ActiveModel {} diff --git a/src/model/object.rs b/src/model/object.rs index 731288c5..1c20ad19 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -116,6 +116,12 @@ pub enum Relation { #[sea_orm(has_many = "super::attachment::Entity")] Attachment, + + #[sea_orm(has_many = "super::like::Entity")] + Like, + + #[sea_orm(has_many = "super::share::Entity")] + Share, } impl Related for Entity { @@ -142,4 +148,16 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Like.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Share.def() + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/src/model/share.rs b/src/model/share.rs index 405d176f..e677cf98 100644 --- a/src/model/share.rs +++ b/src/model/share.rs @@ -11,6 +11,19 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm( + belongs_to = "super::object::Entity", + from = "Column::Shares", + to = "super::object::Column::Id", + )] + Object +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Object.def() + } +} impl ActiveModelBehavior for ActiveModel {}