()
| 7 | |
| 8 | #[sea_orm_macros::test] |
| 9 | async 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] |
| 47 | async fn loader_load_many() -> Result<(), DbErr> { |
nothing calls this directly
no test coverage detected