deep nest load with ModelEx
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
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)
.await
However, 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the self-referencing ModelEx reproduction and the Entity::load().with(...) calls shown in the issue. Investigate nested relation loading for Children and Website, including the reported compile error for the tuple form; done means each child has its website loaded as expected and the supported query form works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100