MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / find_also_linked

Method find_also_linked

src/query/join.rs:67–110  ·  view source on GitHub ↗

Left Join with a Linked Entity and select both Entity.

(self, l: L)

Source from the content-addressed store, hash-verified

65
66 /// Left Join with a Linked Entity and select both Entity.
67 pub fn find_also_linked<L, T>(self, l: L) -> SelectTwo<E, T>
68 where
69 L: Linked<FromEntity = E, ToEntity = T>,
70 T: EntityTrait,
71 {
72 let mut slf = self;
73 for (i, mut rel) in l.link().into_iter().enumerate() {
74 let to_tbl = Alias::new(format!("r{i}")).into_iden();
75 let from_tbl = if i > 0 {
76 Alias::new(format!("r{}", i - 1)).into_iden()
77 } else {
78 unpack_table_ref(&rel.from_tbl)
79 };
80 let table_ref = rel.to_tbl;
81
82 let mut condition = Condition::all().add(join_tbl_on_condition(
83 SeaRc::clone(&from_tbl),
84 SeaRc::clone(&to_tbl),
85 rel.from_col,
86 rel.to_col,
87 ));
88 if let Some(f) = rel.on_condition.take() {
89 condition = condition.add(f(SeaRc::clone(&from_tbl), SeaRc::clone(&to_tbl)));
90 }
91
92 slf.query()
93 .join_as(JoinType::LeftJoin, table_ref, to_tbl, condition);
94 }
95 slf = slf.apply_alias(SelectA.as_str());
96 let mut select_two = SelectTwo::new_without_prepare(slf.query);
97 for col in <T::Column as Iterable>::iter() {
98 let alias = format!("{}{}", SelectB.as_str(), col.as_str());
99 let expr = Expr::col((
100 Alias::new(format!("r{}", l.link().len() - 1)).into_iden(),
101 col.into_iden(),
102 ));
103 select_two.query().expr(SelectExpr {
104 expr: col.select_as(expr),
105 alias: Some(SeaRc::new(Alias::new(alias))),
106 window: None,
107 });
108 }
109 select_two
110 }
111
112 /// Left Join with a Linked Entity and select Entity as a `Vec`.
113 pub fn find_with_linked<L, T>(self, l: L) -> SelectTwoMany<E, T>

Callers 3

active_enum_find_linkedFunction · 0.80
linkedFunction · 0.80

Calls 13

join_tbl_on_conditionFunction · 0.85
into_iterMethod · 0.80
addMethod · 0.80
takeMethod · 0.80
join_asMethod · 0.80
apply_aliasMethod · 0.80
exprMethod · 0.80
unpack_table_refFunction · 0.70
newFunction · 0.50
linkMethod · 0.45
queryMethod · 0.45
as_strMethod · 0.45

Tested by 3

active_enum_find_linkedFunction · 0.64
linkedFunction · 0.64