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

Function loader_load_one

tests/loader_tests.rs:9–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8#[sea_orm_macros::test]
9async fn loader_load_one() -> Result<(), DbErr> {
10 let ctx = TestContext::new("loader_test_load_one").await;
11 create_tables(&ctx.db).await?;
12
13 let bakery_0 = insert_bakery(&ctx.db, "SeaSide Bakery").await?;
14
15 let baker_1 = insert_baker(&ctx.db, "Baker 1", bakery_0.id).await?;
16 let baker_2 = insert_baker(&ctx.db, "Baker 2", bakery_0.id).await?;
17 let baker_3 = baker::ActiveModel {
18 name: Set("Baker 3".to_owned()),
19 contact_details: Set(serde_json::json!({})),
20 bakery_id: Set(None),
21 ..Default::default()
22 }
23 .insert(&ctx.db)
24 .await?;
25
26 let bakers = baker::Entity::find().all(&ctx.db).await?;
27 let bakeries = bakers.load_one(bakery::Entity, &ctx.db).await?;
28
29 assert_eq!(bakers, [baker_1, baker_2, baker_3]);
30 assert_eq!(bakeries, [Some(bakery_0.clone()), Some(bakery_0), None]);
31
32 // has many find, should use load_many instead
33 let bakeries = bakery::Entity::find().all(&ctx.db).await?;
34 let bakers = bakeries.load_one(baker::Entity, &ctx.db).await;
35
36 assert_eq!(
37 bakers,
38 Err(DbErr::Query(RuntimeErr::Internal(
39 "Relation is HasMany instead of HasOne".to_string()
40 )))
41 );
42
43 Ok(())
44}
45
46#[sea_orm_macros::test]
47async fn loader_load_many() -> Result<(), DbErr> {

Callers

nothing calls this directly

Calls 7

insert_bakeryFunction · 0.85
insert_bakerFunction · 0.85
load_oneMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
insertMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected