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)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user