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

Function find_one_to_many

examples/basic/src/select.rs:92–114  ·  view source on GitHub ↗
(db: &DbConn)

Source from the content-addressed store, hash-verified

90}
91
92async fn find_one_to_many(db: &DbConn) -> Result<(), DbErr> {
93 print!("find cakes with fruits: ");
94
95 let cakes_with_fruits: Vec<(cake::Model, Vec<fruit::Model>)> = Cake::find()
96 .find_with_related(fruit::Entity)
97 .all(db)
98 .await?;
99
100 println!("with loader: ");
101 let cakes: Vec<cake::Model> = Cake::find().all(db).await?;
102 let fruits: Vec<Vec<fruit::Model>> = cakes.load_many(Fruit, db).await?;
103
104 println!();
105 for (left, right) in cakes_with_fruits
106 .into_iter()
107 .zip(cakes.into_iter().zip(fruits.into_iter()))
108 {
109 println!("{left:?}\n");
110 assert_eq!(left, right);
111 }
112
113 Ok(())
114}
115
116impl Cake {
117 fn find_by_name(name: &str) -> Select<Self> {

Callers 1

all_about_selectFunction · 0.85

Calls 4

find_with_relatedMethod · 0.80
load_manyMethod · 0.80
into_iterMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected