Non-static link

This commit is contained in:
Billy Chan 2021-08-28 20:20:34 +08:00
parent bfaa7d4539
commit 9db0748c64
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7
5 changed files with 9 additions and 9 deletions

View File

@ -17,11 +17,11 @@ pub trait ModelTrait: Clone + Debug {
<Self::Entity as Related<R>>::find_related().belongs_to(self)
}
fn find_linked<L>(&self, _: L) -> Select<L::ToEntity>
fn find_linked<L>(&self, l: L) -> Select<L::ToEntity>
where
L: Linked<FromEntity = Self::Entity>,
{
L::find_linked()
l.find_linked()
}
}

View File

@ -33,11 +33,11 @@ pub trait Linked {
type ToEntity: EntityTrait;
fn link() -> Vec<RelationDef>;
fn link(&self) -> Vec<RelationDef>;
fn find_linked() -> Select<Self::ToEntity> {
fn find_linked(&self) -> Select<Self::ToEntity> {
let mut select = Select::new();
for rel in Self::link().into_iter().rev() {
for rel in self.link().into_iter().rev() {
select = select.join_rev(JoinType::InnerJoin, rel);
}
select

View File

@ -59,13 +59,13 @@ where
}
/// Left Join with a Linked Entity and select both Entity.
pub fn find_also_linked<L, T>(self, _: L) -> SelectTwo<E, T>
pub fn find_also_linked<L, T>(self, l: L) -> SelectTwo<E, T>
where
L: Linked<FromEntity = E, ToEntity = T>,
T: EntityTrait,
{
let mut slf = self;
for rel in L::link() {
for rel in l.link() {
slf = slf.join(JoinType::LeftJoin, rel);
}
slf.select_also(T::default())

View File

@ -80,7 +80,7 @@ impl Linked for CakeToFilling {
type ToEntity = super::filling::Entity;
fn link() -> Vec<RelationDef> {
fn link(&self) -> Vec<RelationDef> {
vec![
super::cake_filling::Relation::Cake.def().rev(),
super::cake_filling::Relation::Filling.def(),

View File

@ -88,7 +88,7 @@ impl Linked for BakedForCustomer {
type ToEntity = super::customer::Entity;
fn link() -> Vec<RelationDef> {
fn link(&self) -> Vec<RelationDef> {
vec![
super::cakes_bakers::Relation::Baker.def().rev(),
super::cakes_bakers::Relation::Cake.def(),