Non-static link
This commit is contained in:
parent
bfaa7d4539
commit
9db0748c64
@ -17,11 +17,11 @@ pub trait ModelTrait: Clone + Debug {
|
|||||||
<Self::Entity as Related<R>>::find_related().belongs_to(self)
|
<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
|
where
|
||||||
L: Linked<FromEntity = Self::Entity>,
|
L: Linked<FromEntity = Self::Entity>,
|
||||||
{
|
{
|
||||||
L::find_linked()
|
l.find_linked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,11 +33,11 @@ pub trait Linked {
|
|||||||
|
|
||||||
type ToEntity: EntityTrait;
|
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();
|
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 = select.join_rev(JoinType::InnerJoin, rel);
|
||||||
}
|
}
|
||||||
select
|
select
|
||||||
|
@ -59,13 +59,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Left Join with a Linked Entity and select both Entity.
|
/// 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
|
where
|
||||||
L: Linked<FromEntity = E, ToEntity = T>,
|
L: Linked<FromEntity = E, ToEntity = T>,
|
||||||
T: EntityTrait,
|
T: EntityTrait,
|
||||||
{
|
{
|
||||||
let mut slf = self;
|
let mut slf = self;
|
||||||
for rel in L::link() {
|
for rel in l.link() {
|
||||||
slf = slf.join(JoinType::LeftJoin, rel);
|
slf = slf.join(JoinType::LeftJoin, rel);
|
||||||
}
|
}
|
||||||
slf.select_also(T::default())
|
slf.select_also(T::default())
|
||||||
|
@ -80,7 +80,7 @@ impl Linked for CakeToFilling {
|
|||||||
|
|
||||||
type ToEntity = super::filling::Entity;
|
type ToEntity = super::filling::Entity;
|
||||||
|
|
||||||
fn link() -> Vec<RelationDef> {
|
fn link(&self) -> Vec<RelationDef> {
|
||||||
vec![
|
vec![
|
||||||
super::cake_filling::Relation::Cake.def().rev(),
|
super::cake_filling::Relation::Cake.def().rev(),
|
||||||
super::cake_filling::Relation::Filling.def(),
|
super::cake_filling::Relation::Filling.def(),
|
||||||
|
@ -88,7 +88,7 @@ impl Linked for BakedForCustomer {
|
|||||||
|
|
||||||
type ToEntity = super::customer::Entity;
|
type ToEntity = super::customer::Entity;
|
||||||
|
|
||||||
fn link() -> Vec<RelationDef> {
|
fn link(&self) -> Vec<RelationDef> {
|
||||||
vec![
|
vec![
|
||||||
super::cakes_bakers::Relation::Baker.def().rev(),
|
super::cakes_bakers::Relation::Baker.def().rev(),
|
||||||
super::cakes_bakers::Relation::Cake.def(),
|
super::cakes_bakers::Relation::Cake.def(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user