-
-
Notifications
You must be signed in to change notification settings - Fork 668
Open
Description
Motivation
With the following self-referencing model
#[sea_orm::model]
#[derive(Clone, Debug, DeriveEntityModel, Deserialize, Eq, PartialEq, Serialize)]
#[sea_orm(table_name = "extractor")]
#[non_exhaustive]
struct Model {
#[sea_orm(primary_key)]
id: i64,
#[sea_orm(unique_key = "unique_selector")]
parent_id: Option<i64>,
#[sea_orm(
self_ref,
from = "parent_id",
relation_enum = "Parent",
relation_reverse = "Children",
to = "id"
)]
parent: HasOne<Entity>,
#[sea_orm(self_ref, relation_enum = "Children", relation_reverse = "Parent")]
children: HasMany<Entity>,
#[sea_orm(unique_key = "unique_selector")]
website_id: i64,
#[sea_orm(belongs_to, from = "website_id", to = "id")]
website: HasOne<super::website::Entity>,
}it can be loaded as
extractor::Entity::load()
.with(extractor::Relation::Children) // loading the children
// .with((extractor::Relation::Children, extractor::Relation::Website)) this doesn't work, see the error at the end.
.with(website::Entity)
.filter(website::Column::Id.eq(website_id))
.filter(extractor::Column::ParentId.is_null())
.all(&state.db)
.awaitHowever, it does not load website for the children
ModelEx {
id: 8,
parent_id: None,
parent: Unloaded,
children: Loaded(
[
ModelEx {
id: 9,
parent_id: Some(
8,
),
parent: Unloaded,
children: Unloaded,
website_id: 1,
website: Unloaded, // website is not loaded in the second/child level
},
],
),
website_id: 1,
website: Loaded( // <<< website is loaded on the first/parent level
ModelEx {
id: 1,
name: "",
url: "",
extractors: Unloaded,
},
),
}Additional Information
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels