SeaQL/sea-orm

LoaderTrait: load_many fails in partial models

04cfb1ed opened this issue · 0 comments

Description

I have a EntityOne with a lot of fields, I use a Partial Model to get only the required fields and I want to use the Loadertrait to get related models (I need to get more than three models, therefore I can't use 'related' functions)

Steps to Reproduce

Having an EntityOne with a one-to-many Relation, create a PartialModel

#[derive(Debug, DerivePartialModel, FromQueryResult)]
#[sea_orm(entity = "EntityOne")]
pub(crate) struct PartialEntityOne {
    pub id: i32,
    pub name: String,
    pub is_active: bool,
    pub pub_date: DateTimeWithTimeZone,
}
let paginator = EntityOne ::find()
            .into_partial_model::<PartialEntityOne>()
            .paginate(&db, page_size);

// Paginator is not necessary but is similar to the code built
let entities = paginator.fetch_page(page.unwrap_or(1) - 1).await?;

let another_entities = entities.load_many(EntityTwo::Entity, &db).await?;

Expected Behavior

Get the another entities

Actual Behavior

the method `load_many` exists for struct `Vec<PartialEntityOne>`, but its trait bounds were not satisfied
the following trait bounds were not satisfied:
`PartialEntityOne: ModelTrait`
which is required by `Vec<PartialAccuracy>: LoaderTrait
code.rs(x, 9): doesn't satisfy `PartialAccuracy: ModelTrait`
mod.rs(396, 1): doesn't satisfy `Vec<PartialAccuracy>: LoaderTrait`
model.rs(12, 1): the trait `ModelTrait` must be implemented

Workarounds

I would have to use the full Entity with all unnecessary fields to use the LoaderTrait

Versions

sea-orm v0.12.9