فهرست منبع

✨ feat(models): 添加菜单商品、SKU及规格的关系定义和序列化支持

陈雪 3 هفته پیش
والد
کامیت
eb1d96eed8

+ 10 - 1
src-tauri/src/models/menu_cate.rs

@@ -26,6 +26,15 @@ pub struct Model {
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
-pub enum Relation {}
+pub enum Relation {
+    #[sea_orm(has_many = "super::menu_commodity::Entity")]
+    MenuCommodity,
+}
+
+impl Related<super::menu_commodity::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::MenuCommodity.def()
+    }
+}
 
 impl ActiveModelBehavior for ActiveModel {}

+ 34 - 4
src-tauri/src/models/menu_commodity.rs

@@ -1,16 +1,15 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
+use serde::Serialize;
 
-#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
 #[sea_orm(table_name = "menu_commodity")]
 pub struct Model {
     #[sea_orm(primary_key)]
     pub id: i32,
     #[sea_orm(column_type = "Text", nullable)]
     pub r#type: Option<String>,
-    pub merchant_id: Option<i32>,
-    pub store_id: Option<i32>,
     #[sea_orm(column_type = "Text", nullable)]
     pub name: Option<String>,
     pub cate_id: Option<i32>,
@@ -50,6 +49,37 @@ pub struct Model {
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
-pub enum Relation {}
+pub enum Relation {
+    #[sea_orm(
+        belongs_to = "super::menu_cate::Entity",
+        from = "Column::CateId",
+        to = "super::menu_cate::Column::Id",
+        on_update = "NoAction",
+        on_delete = "NoAction"
+    )]
+    MenuCate,
+    #[sea_orm(has_many = "super::menu_sku::Entity")]
+    MenuSku,
+    #[sea_orm(has_many = "super::menu_spec::Entity")]
+    MenuSpec,
+}
+
+impl Related<super::menu_cate::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::MenuCate.def()
+    }
+}
+
+impl Related<super::menu_sku::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::MenuSku.def()
+    }
+}
+
+impl Related<super::menu_spec::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::MenuSpec.def()
+    }
+}
 
 impl ActiveModelBehavior for ActiveModel {}

+ 14 - 0
src-tauri/src/models/menu_sku.rs

@@ -22,10 +22,24 @@ pub struct Model {
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
 pub enum Relation {
+    #[sea_orm(
+        belongs_to = "super::menu_commodity::Entity",
+        from = "Column::GoodsId",
+        to = "super::menu_commodity::Column::Id",
+        on_update = "NoAction",
+        on_delete = "NoAction"
+    )]
+    MenuCommodity,
     #[sea_orm(has_many = "super::menu_sku_spec::Entity")]
     MenuSkuSpec,
 }
 
+impl Related<super::menu_commodity::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::MenuCommodity.def()
+    }
+}
+
 impl Related<super::menu_sku_spec::Entity> for Entity {
     fn to() -> RelationDef {
         Relation::MenuSkuSpec.def()

+ 2 - 1
src-tauri/src/models/menu_sku_spec.rs

@@ -1,6 +1,7 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
+use serde::Serialize;
 
 #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
 #[sea_orm(table_name = "menu_sku_spec")]
@@ -11,7 +12,7 @@ pub struct Model {
     pub spec_id: i32,
 }
 
-#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, Serialize)]
 pub enum Relation {
     #[sea_orm(
         belongs_to = "super::menu_sku::Entity",

+ 16 - 1
src-tauri/src/models/menu_spec.rs

@@ -1,8 +1,9 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
+use serde::Serialize;
 
-#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
 #[sea_orm(table_name = "menu_spec")]
 pub struct Model {
     #[sea_orm(primary_key)]
@@ -18,10 +19,24 @@ pub struct Model {
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
 pub enum Relation {
+    #[sea_orm(
+        belongs_to = "super::menu_commodity::Entity",
+        from = "Column::GoodsId",
+        to = "super::menu_commodity::Column::Id",
+        on_update = "NoAction",
+        on_delete = "NoAction"
+    )]
+    MenuCommodity,
     #[sea_orm(has_many = "super::menu_sku_spec::Entity")]
     MenuSkuSpec,
 }
 
+impl Related<super::menu_commodity::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::MenuCommodity.def()
+    }
+}
+
 impl Related<super::menu_sku_spec::Entity> for Entity {
     fn to() -> RelationDef {
         Relation::MenuSkuSpec.def()

+ 1 - 1
src-tauri/src/models/prelude.rs

@@ -1,7 +1,7 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 pub use super::menu_cate::Entity as MenuCate;
-// pub use super::menu_commodity::Entity as MenuCommodity;
+pub use super::menu_commodity::Entity as MenuCommodity;
 // pub use super::menu_sku::Entity as MenuSku;
 // pub use super::menu_sku_spec::Entity as MenuSkuSpec;
 // pub use super::menu_spec::Entity as MenuSpec;