use std::marker::PhantomData;
use arcature_db::sea_orm;
use crate::error::DataError;
use crate::query::Query;
pub struct Relation<R>
where
R: sea_orm::EntityTrait,
{
_related: PhantomData<R>,
}
#[must_use]
pub fn of<R>() -> Relation<R>
where
R: sea_orm::EntityTrait,
{
Relation {
_related: PhantomData,
}
}
impl<'db, E> Query<'db, E>
where
E: sea_orm::EntityTrait,
{
pub async fn with<R>(
self,
_relation: Relation<R>,
) -> Result<Vec<(E::Model, Option<R::Model>)>, DataError>
where
R: sea_orm::EntityTrait + Default,
E: sea_orm::Related<R>,
{
self.select
.find_also_related(R::default())
.all(self.db.orm())
.await
.map_err(DataError::from)
}
}