ad ded migration

This commit is contained in:
2025-02-07 23:30:27 +01:00
parent 19eff26934
commit 6d08c39a6d
19 changed files with 6521 additions and 2 deletions

View File

@@ -0,0 +1,61 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use crate::base::entity::BaseEntity;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "product")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub description: Option<String>,
// ... other product-specific fields ...
pub created_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
// ActiveModel - CORRECT STRUCTURE (No DeriveModel!)
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ActiveModel {
pub id: sea_orm::ActiveValue<i32>,
pub name: sea_orm::ActiveValue<String>,
pub description: sea_orm::ActiveValue<Option<String>>,
// ... other fields ...
pub created_at: sea_orm::ActiveValue<DateTime>,
pub updated_at: sea_orm::ActiveValue<DateTime>,
}
impl Entity {
pub fn find_by_id(id: i32) -> Select<'static> {
Self::find().filter(Column::Id.eq(id))
}
}
// Implement get and set methods for the ActiveModel
impl ActiveModel {
pub fn get_name(&self) -> Option<String> {
match self.name {
sea_orm::ActiveValue::Set(val) => Some(val),
_ => None
}
}
pub fn set_name(&mut self, val: String) {
self.name = sea_orm::Set(val);
}
pub fn get_description(&self) -> Option<String> {
match self.description {
sea_orm::ActiveValue::Set(val) => Some(val),
_ => None
}
}
pub fn set_description(&mut self, val: String) {
self.description = sea_orm::Set(val);
}
}