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

Function related

tests/relational_tests.rs:487–728  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

485
486#[sea_orm_macros::test]
487pub async fn related() -> Result<(), DbErr> {
488 use sea_orm::{SelectA, SelectB};
489
490 let ctx = TestContext::new("test_related").await;
491 create_tables(&ctx.db).await?;
492
493 // SeaSide Bakery
494 let seaside_bakery = bakery::ActiveModel {
495 name: Set("SeaSide Bakery".to_owned()),
496 profit_margin: Set(10.4),
497 ..Default::default()
498 };
499 let seaside_bakery_res = Bakery::insert(seaside_bakery).exec(&ctx.db).await?;
500
501 // Bob's Baker
502 let baker_bob = baker::ActiveModel {
503 name: Set("Baker Bob".to_owned()),
504 contact_details: Set(serde_json::json!({
505 "mobile": "+61424000000",
506 "home": "0395555555",
507 "address": "12 Test St, Testville, Vic, Australia"
508 })),
509 bakery_id: Set(Some(seaside_bakery_res.last_insert_id)),
510 ..Default::default()
511 };
512 let _baker_bob_res = Baker::insert(baker_bob).exec(&ctx.db).await?;
513
514 // Bobby's Baker
515 let baker_bobby = baker::ActiveModel {
516 name: Set("Baker Bobby".to_owned()),
517 contact_details: Set(serde_json::json!({
518 "mobile": "+85212345678",
519 })),
520 bakery_id: Set(Some(seaside_bakery_res.last_insert_id)),
521 ..Default::default()
522 };
523 let _baker_bobby_res = Baker::insert(baker_bobby).exec(&ctx.db).await?;
524
525 // Terres Bakery
526 let terres_bakery = bakery::ActiveModel {
527 name: Set("Terres Bakery".to_owned()),
528 profit_margin: Set(13.5),
529 ..Default::default()
530 };
531 let terres_bakery_res = Bakery::insert(terres_bakery).exec(&ctx.db).await?;
532
533 // Ada's Baker
534 let baker_ada = baker::ActiveModel {
535 name: Set("Baker Ada".to_owned()),
536 contact_details: Set(serde_json::json!({
537 "mobile": "+61424000000",
538 "home": "0395555555",
539 "address": "12 Test St, Testville, Vic, Australia"
540 })),
541 bakery_id: Set(Some(terres_bakery_res.last_insert_id)),
542 ..Default::default()
543 };
544 let _baker_ada_res = Baker::insert(baker_ada).exec(&ctx.db).await?;

Callers

nothing calls this directly

Calls 15

order_by_ascMethod · 0.80
column_asMethod · 0.80
select_onlyMethod · 0.80
find_also_relatedMethod · 0.80
unwrapMethod · 0.80
filterMethod · 0.80
find_with_relatedMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
execMethod · 0.45
allMethod · 0.45
into_modelMethod · 0.45

Tested by

no test coverage detected