From e558dc8584cb28fead316dc588582719adf2882f Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 27 Sep 2021 12:13:57 +0800 Subject: [PATCH] Move `impl Linked` to entity_linked module --- src/query/join.rs | 10 +++++----- src/tests_cfg/cake.rs | 33 --------------------------------- src/tests_cfg/cake_expanded.rs | 16 ---------------- src/tests_cfg/entity_linked.rs | 34 ++++++++++++++++++++++++++++++++++ src/tests_cfg/mod.rs | 1 + 5 files changed, 40 insertions(+), 54 deletions(-) create mode 100644 src/tests_cfg/entity_linked.rs diff --git a/src/query/join.rs b/src/query/join.rs index b0243c59..50592933 100644 --- a/src/query/join.rs +++ b/src/query/join.rs @@ -74,7 +74,7 @@ where #[cfg(test)] mod tests { - use crate::tests_cfg::{cake, cake_filling, cake_filling_price, filling, fruit}; + use crate::tests_cfg::{cake, cake_filling, cake_filling_price, entity_linked, filling, fruit}; use crate::{ColumnTrait, DbBackend, EntityTrait, ModelTrait, QueryFilter, QueryTrait}; use pretty_assertions::assert_eq; @@ -244,7 +244,7 @@ mod tests { assert_eq!( cake_model - .find_linked(cake::CakeToFilling) + .find_linked(entity_linked::CakeToFilling) .build(DbBackend::MySql) .to_string(), [ @@ -267,7 +267,7 @@ mod tests { assert_eq!( cake_model - .find_linked(cake::CakeToFillingVendor) + .find_linked(entity_linked::CakeToFillingVendor) .build(DbBackend::MySql) .to_string(), [ @@ -286,7 +286,7 @@ mod tests { fn join_12() { assert_eq!( cake::Entity::find() - .find_also_linked(cake::CakeToFilling) + .find_also_linked(entity_linked::CakeToFilling) .build(DbBackend::MySql) .to_string(), [ @@ -304,7 +304,7 @@ mod tests { fn join_13() { assert_eq!( cake::Entity::find() - .find_also_linked(cake::CakeToFillingVendor) + .find_also_linked(entity_linked::CakeToFillingVendor) .build(DbBackend::MySql) .to_string(), [ diff --git a/src/tests_cfg/cake.rs b/src/tests_cfg/cake.rs index eb8c937e..8628492b 100644 --- a/src/tests_cfg/cake.rs +++ b/src/tests_cfg/cake.rs @@ -31,37 +31,4 @@ impl Related for Entity { } } -#[derive(Debug)] -pub struct CakeToFilling; - -impl Linked for CakeToFilling { - type FromEntity = Entity; - - type ToEntity = super::filling::Entity; - - fn link(&self) -> Vec { - vec![ - super::cake_filling::Relation::Cake.def().rev(), - super::cake_filling::Relation::Filling.def(), - ] - } -} - -#[derive(Debug)] -pub struct CakeToFillingVendor; - -impl Linked for CakeToFillingVendor { - type FromEntity = Entity; - - type ToEntity = super::vendor::Entity; - - fn link(&self) -> Vec { - vec![ - super::cake_filling::Relation::Cake.def().rev(), - super::cake_filling::Relation::Filling.def(), - super::filling::Relation::Vendor.def(), - ] - } -} - impl ActiveModelBehavior for ActiveModel {} diff --git a/src/tests_cfg/cake_expanded.rs b/src/tests_cfg/cake_expanded.rs index 0eeb0738..b4306313 100644 --- a/src/tests_cfg/cake_expanded.rs +++ b/src/tests_cfg/cake_expanded.rs @@ -75,20 +75,4 @@ impl Related for Entity { } } -#[derive(Debug)] -pub struct CakeToFilling; - -impl Linked for CakeToFilling { - type FromEntity = Entity; - - type ToEntity = super::filling::Entity; - - fn link(&self) -> Vec { - vec![ - super::cake_filling::Relation::Cake.def().rev(), - super::cake_filling::Relation::Filling.def(), - ] - } -} - impl ActiveModelBehavior for ActiveModel {} diff --git a/src/tests_cfg/entity_linked.rs b/src/tests_cfg/entity_linked.rs new file mode 100644 index 00000000..a4057a6c --- /dev/null +++ b/src/tests_cfg/entity_linked.rs @@ -0,0 +1,34 @@ +use crate::entity::prelude::*; + +#[derive(Debug)] +pub struct CakeToFilling; + +impl Linked for CakeToFilling { + type FromEntity = super::cake::Entity; + + type ToEntity = super::filling::Entity; + + fn link(&self) -> Vec { + vec![ + super::cake_filling::Relation::Cake.def().rev(), + super::cake_filling::Relation::Filling.def(), + ] + } +} + +#[derive(Debug)] +pub struct CakeToFillingVendor; + +impl Linked for CakeToFillingVendor { + type FromEntity = super::cake::Entity; + + type ToEntity = super::vendor::Entity; + + fn link(&self) -> Vec { + vec![ + super::cake_filling::Relation::Cake.def().rev(), + super::cake_filling::Relation::Filling.def(), + super::filling::Relation::Vendor.def(), + ] + } +} diff --git a/src/tests_cfg/mod.rs b/src/tests_cfg/mod.rs index 9e5d4de0..6bc86aed 100644 --- a/src/tests_cfg/mod.rs +++ b/src/tests_cfg/mod.rs @@ -4,6 +4,7 @@ pub mod cake; pub mod cake_expanded; pub mod cake_filling; pub mod cake_filling_price; +pub mod entity_linked; pub mod filling; pub mod fruit; pub mod vendor;