【发布时间】:2021-11-03 23:20:34
【问题描述】:
使用 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>
}
我得到的错误是:
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`
我认为必须使用另一个宏,一个不需要关系的宏,但我在文档中找不到它。
【问题讨论】:
-
你好,你看过下面的例子吗? (github.com/SeaQL/sea-orm/tree/master/examples/rocket_example)。它只使用一张桌子