Test case
This commit is contained in:
parent
2ea4be9350
commit
d5cdeb1fe0
@ -25,7 +25,7 @@ where
|
||||
}
|
||||
|
||||
fn find_related() -> Select<R> {
|
||||
Select::<R>::new().join_rev(JoinType::InnerJoin, Self::to())
|
||||
Select::<R>::new().join_join_rev(JoinType::InnerJoin, Self::to(), Self::via())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,15 @@ pub trait QueryHelper: Sized {
|
||||
self.join(join, rel)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn join_join_rev(mut self, join: JoinType, rel: RelationDef, via: Option<RelationDef>) -> Self {
|
||||
self = self.join_rev(join, rel);
|
||||
if let Some(via) = via {
|
||||
self = self.join_rev(join, via)
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Join via [`RelationDef`].
|
||||
fn join(mut self, join: JoinType, rel: RelationDef) -> Self {
|
||||
self.query()
|
||||
|
@ -173,4 +173,20 @@ mod tests {
|
||||
.join(" ")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn join_7() {
|
||||
use crate::{Related, Select};
|
||||
|
||||
let find_filling: Select<filling::Entity> = cake::Entity::find_related();
|
||||
assert_eq!(
|
||||
find_filling.build(MysqlQueryBuilder).to_string(),
|
||||
[
|
||||
"SELECT `filling`.`id`, `filling`.`name` FROM `filling`",
|
||||
"INNER JOIN `cake_filling` ON `cake_filling`.`filling_id` = `filling`.`id`",
|
||||
"INNER JOIN `cake` ON `cake`.`id` = `cake_filling`.`cake_id`",
|
||||
]
|
||||
.join(" ")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user