Skip to content
Closed
Prev Previous commit
Next Next commit
Rename SelectBoth to SelectTwoRequired for clarity and consistency ac…
…ross the codebase
  • Loading branch information
rakshith-ravi committed Mar 6, 2026
commit 47ff4293f3d7e65399c8a7dad10c3c0d74917fdc
20 changes: 10 additions & 10 deletions src/executor/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use super::{
};
use crate::{
ConnectionTrait, DbBackend, EntityTrait, FromQueryResult, IdenStatic, PartialModelTrait,
QueryResult, QuerySelect, Select, SelectA, SelectB, SelectTwo, SelectBoth, SelectTwoMany, Statement,
StreamTrait, TryGetableMany, error::*,
QueryResult, QuerySelect, Select, SelectA, SelectB, SelectTwo, SelectTwoMany,
SelectTwoRequired, Statement, StreamTrait, TryGetableMany, error::*,
};
use futures_util::{Stream, TryStreamExt};
use itertools::Itertools;
Expand Down Expand Up @@ -94,7 +94,7 @@ where

/// Defines a type to get two Models
#[derive(Clone, Debug)]
pub struct SelectBothModel<M, N>
pub struct SelectTwoRequiredModel<M, N>
where
M: FromQueryResult,
N: FromQueryResult,
Expand Down Expand Up @@ -215,7 +215,7 @@ where
}
}

impl<M, N> SelectorTrait for SelectBothModel<M, N>
impl<M, N> SelectorTrait for SelectTwoRequiredModel<M, N>
where
M: FromQueryResult + Sized,
N: FromQueryResult + Sized,
Expand Down Expand Up @@ -678,13 +678,13 @@ where
// we should only count the number of items of the parent model
}

impl<E, F> SelectBoth<E, F>
impl<E, F> SelectTwoRequired<E, F>
where
E: EntityTrait,
F: EntityTrait,
{
/// Perform a conversion into a [SelectBothModel]
pub fn into_model<M, N>(self) -> Selector<SelectBothModel<M, N>>
/// Perform a conversion into a [SelectTwoRequiredModel]
pub fn into_model<M, N>(self) -> Selector<SelectTwoRequiredModel<M, N>>
where
M: FromQueryResult,
N: FromQueryResult,
Expand All @@ -695,8 +695,8 @@ where
}
}

/// Perform a conversion into a [SelectBothModel] with [PartialModel](PartialModelTrait)
pub fn into_partial_model<M, N>(self) -> Selector<SelectBothModel<M, N>>
/// Perform a conversion into a [SelectTwoRequiredModel] with [PartialModel](PartialModelTrait)
pub fn into_partial_model<M, N>(self) -> Selector<SelectTwoRequiredModel<M, N>>
where
M: PartialModelTrait,
N: PartialModelTrait,
Expand All @@ -709,7 +709,7 @@ where

/// Convert the Models into JsonValue
#[cfg(feature = "with-json")]
pub fn into_json(self) -> Selector<SelectBothModel<JsonValue, JsonValue>> {
pub fn into_json(self) -> Selector<SelectTwoRequiredModel<JsonValue, JsonValue>> {
Selector {
query: self.query,
selector: PhantomData,
Expand Down
10 changes: 5 additions & 5 deletions src/query/combine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
ColumnTrait, EntityTrait, IdenStatic, Iterable, QueryTrait, Select, SelectBoth, SelectTwo,
SelectTwoMany,
ColumnTrait, EntityTrait, IdenStatic, Iterable, QueryTrait, Select, SelectTwo, SelectTwoMany,
SelectTwoRequired,
};
use core::marker::PhantomData;
use sea_query::{Iden, IntoIden, Order, SelectExpr, SelectStatement, SimpleExpr};
Expand Down Expand Up @@ -106,12 +106,12 @@ where
}

/// Selects extra Entity and returns it together with the Entity from `Self`
pub fn select_both<F>(mut self, _: F) -> SelectBoth<E, F>
pub fn select_two_required<F>(mut self, _: F) -> SelectTwoRequired<E, F>
where
F: EntityTrait,
{
self = self.apply_alias(SelectA.as_str());
SelectBoth::new(self.into_query())
SelectTwoRequired::new(self.into_query())
}
}

Expand Down Expand Up @@ -168,7 +168,7 @@ where
}
}

impl<E, F> SelectBoth<E, F>
impl<E, F> SelectTwoRequired<E, F>
where
E: EntityTrait,
F: EntityTrait,
Expand Down
8 changes: 4 additions & 4 deletions src/query/join.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
ColumnTrait, EntityTrait, IdenStatic, Iterable, Linked, QueryFilter, QuerySelect, QueryTrait,
Related, Select, SelectA, SelectB, SelectBoth, SelectThree, SelectTwo, SelectTwoMany, TopologyChain,
TopologyStar, find_linked_recursive, join_tbl_on_condition,
Related, Select, SelectA, SelectB, SelectThree, SelectTwo, SelectTwoMany, SelectTwoRequired,
TopologyChain, TopologyStar, find_linked_recursive, join_tbl_on_condition,
};
pub use sea_query::JoinType;
use sea_query::{Condition, Expr, IntoCondition, IntoIden, SelectExpr};
Expand Down Expand Up @@ -64,12 +64,12 @@ where
}

/// Inner Join with a Related Entity and select both Entity.
pub fn find_both_related<R>(self, r: R) -> SelectBoth<E, R>
pub fn find_both_related<R>(self, r: R) -> SelectTwoRequired<E, R>
where
R: EntityTrait,
E: Related<R>,
{
self.inner_join(r).select_both(r)
self.inner_join(r).select_two_required(r)
}

/// Left Join with a Related Entity and select the related Entity as a `Vec`
Expand Down
6 changes: 3 additions & 3 deletions src/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where

/// Defines a structure to perform a SELECT operation on two Models
#[derive(Clone, Debug)]
pub struct SelectBoth<E, F>
pub struct SelectTwoRequired<E, F>
where
E: EntityTrait,
F: EntityTrait,
Expand Down Expand Up @@ -185,7 +185,7 @@ macro_rules! impl_query_trait {
}
}

impl<E, F> $trait for SelectBoth<E, F>
impl<E, F> $trait for SelectTwoRequired<E, F>
where
E: EntityTrait,
F: EntityTrait,
Expand Down Expand Up @@ -329,4 +329,4 @@ macro_rules! select_two {

select_two!(SelectTwo);
select_two!(SelectTwoMany);
select_two!(SelectBoth);
select_two!(SelectTwoRequired);
20 changes: 12 additions & 8 deletions tests/relational_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,18 @@ pub async fn find_both_related() {
.unwrap();

assert_eq!(results.len(), 2);
assert!(results
.iter()
.any(|result| result.1.name == customer_kate.name.clone()
&& result.0.total == kate_order_1.total));
assert!(results
.iter()
.any(|result| result.1.name == customer_kate.name.clone()
&& result.0.total == kate_order_2.total));
assert!(
results
.iter()
.any(|result| result.1.name == customer_kate.name.clone()
&& result.0.total == kate_order_1.total)
);
assert!(
results
.iter()
.any(|result| result.1.name == customer_kate.name.clone()
&& result.0.total == kate_order_2.total)
);

ctx.delete().await;
}
Expand Down