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

Function left_join

tests/relational_tests.rs:19–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std-native-tls --test relational_tests
18#[sea_orm_macros::test]
19pub async fn left_join() {
20 let ctx = TestContext::new("test_left_join").await;
21 create_tables(&ctx.db).await.unwrap();
22
23 let bakery = bakery::ActiveModel {
24 name: Set("SeaSide Bakery".to_owned()),
25 profit_margin: Set(10.4),
26 ..Default::default()
27 }
28 .insert(&ctx.db)
29 .await
30 .expect("could not insert bakery");
31
32 let _baker_1 = baker::ActiveModel {
33 name: Set("Baker 1".to_owned()),
34 contact_details: Set(serde_json::json!({
35 "mobile": "+61424000000",
36 "home": "0395555555",
37 "address": "12 Test St, Testville, Vic, Australia"
38 })),
39 bakery_id: Set(Some(bakery.id)),
40 ..Default::default()
41 }
42 .insert(&ctx.db)
43 .await
44 .expect("could not insert baker");
45
46 let _baker_2 = baker::ActiveModel {
47 name: Set("Baker 2".to_owned()),
48 contact_details: Set(serde_json::json!({})),
49 bakery_id: Set(None),
50 ..Default::default()
51 }
52 .insert(&ctx.db)
53 .await
54 .expect("could not insert baker");
55
56 #[derive(Debug, FromQueryResult)]
57 struct SelectResult {
58 name: String,
59 bakery_name: Option<String>,
60 }
61
62 let select = baker::Entity::find()
63 .left_join(bakery::Entity)
64 .select_only()
65 .column(baker::Column::Name)
66 .column_as(bakery::Column::Name, "bakery_name")
67 .filter(baker::Column::Name.contains("Baker 1"));
68
69 let result = select
70 .clone()
71 .into_model::<SelectResult>()
72 .one(&ctx.db)
73 .await
74 .unwrap()
75 .unwrap();
76 assert_eq!(result.name.as_str(), "Baker 1");

Callers

nothing calls this directly

Calls 12

unwrapMethod · 0.80
filterMethod · 0.80
column_asMethod · 0.80
columnMethod · 0.80
select_onlyMethod · 0.80
left_joinMethod · 0.80
containsMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
insertMethod · 0.45
oneMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected