toasty_driver_integration_suite/tests/
select_projection_embed.rs1use crate::prelude::*;
7
8#[derive(Debug, toasty::Embed)]
9struct Address {
10 street: String,
11 city: String,
12}
13
14#[derive(Debug, toasty::Model)]
15struct Customer {
16 #[key]
17 id: i64,
18 name: String,
19 address: Address,
20}
21
22#[driver_test(requires(sql))]
23pub async fn select_embed_subfield(test: &mut Test) -> Result<()> {
24 let mut db = test.setup_db(models!(Customer)).await;
25
26 Customer::create()
27 .id(1_i64)
28 .name("Alice")
29 .address(Address {
30 street: "123 Main St".to_string(),
31 city: "Springfield".to_string(),
32 })
33 .exec(&mut db)
34 .await?;
35
36 let cities: Vec<String> = Customer::all()
37 .select(Customer::fields().address().city())
38 .exec(&mut db)
39 .await?;
40
41 assert_eq!(cities, vec!["Springfield".to_string()]);
42
43 Ok(())
44}