使用 SeaOrm,我想创建一个没有关系的模型。本质上是一个带有一张表的数据库。
这看起来应该非常简单,但是文档没有涵盖这一点,并且DeriveEntityModel宏需要存在实体关系的所有样板。
我想要的是:
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "device")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_name = "uuid")]
pub uuid: Uuid,
#[sea_orm(column_name = "location")]
pub location: Option<String>,
#[sea_orm(column_name = "lastHeard")]
pub lastHeard: Option<DateTime>
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
cannot find type `Relation` in this scope
help: you might have meant to use the associated type: `Self::Relation`rustc(E0412)
the trait bound `models::device::ActiveModel: sea_orm::ActiveModelBehavior` is not satisfied
the trait `sea_orm::ActiveModelBehavior` is not implemented for `models::device::ActiveModel`
Run Code Online (Sandbox Code Playgroud)
我想必须有另一个宏可以使用,一个不需要关系的宏,但我在文档中找不到它。
小智 5
感谢您尝试 SeaORM。尝试定义一个空的关系枚举,如下所示。
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "device")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_name = "uuid")]
pub uuid: Uuid,
#[sea_orm(column_name = "location")]
pub location: Option<String>,
#[sea_orm(column_name = "lastHeard")]
pub lastHeard: Option<DateTime>
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
944 次 |
| 最近记录: |