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

Function select_three

tests/relational_tests.rs:1094–1186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1092
1093#[sea_orm_macros::test]
1094pub async fn select_three() -> Result<(), DbErr> {
1095 use common::bakery_chain::*;
1096
1097 let ctx = TestContext::new("test_select_three").await;
1098 create_tables(&ctx.db).await?;
1099
1100 seed_data::init_1(&ctx, true).await;
1101
1102 let items: Vec<(order::Model, Option<customer::Model>)> = order::Entity::find()
1103 .find_also_related(customer::Entity)
1104 .order_by_asc(order::Column::Id)
1105 .all(&ctx.db)
1106 .await
1107 .unwrap();
1108
1109 let order = order::Model {
1110 id: 101,
1111 total: Decimal::from(10),
1112 bakery_id: 42,
1113 customer_id: 11,
1114 placed_at: DateTime::UNIX_EPOCH,
1115 };
1116
1117 let customer = customer::Model {
1118 id: 11,
1119 name: "Bob".to_owned(),
1120 notes: Some("Sweet tooth".to_owned()),
1121 };
1122 assert_eq!(items.len(), 1);
1123 assert_eq!(items[0].0, order);
1124 assert_eq!(items[0].1.as_ref().unwrap(), &customer);
1125
1126 let items: Vec<(
1127 order::Model,
1128 Option<customer::Model>,
1129 Option<lineitem::Model>,
1130 )> = order::Entity::find()
1131 .find_also_related(customer::Entity)
1132 .find_also_related(lineitem::Entity)
1133 .order_by_asc(order::Column::Id)
1134 .order_by_asc(lineitem::Column::Id)
1135 .all(&ctx.db)
1136 .await
1137 .unwrap();
1138
1139 let line_1 = lineitem::Model {
1140 id: 1,
1141 price: 2.into(),
1142 quantity: 2,
1143 order_id: 101,
1144 cake_id: 13,
1145 };
1146
1147 let line_2 = lineitem::Model {
1148 id: 2,
1149 price: 3.into(),
1150 quantity: 2,
1151 order_id: 101,

Callers

nothing calls this directly

Calls 9

init_1Function · 0.85
unwrapMethod · 0.80
order_by_ascMethod · 0.80
find_also_relatedMethod · 0.80
and_also_relatedMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
allMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected