(db: &DbConn)
| 176 | } |
| 177 | |
| 178 | async fn find_many_to_many(db: &DbConn) -> Result<(), DbErr> { |
| 179 | print!("find cakes and fillings: "); |
| 180 | |
| 181 | let cakes_with_fillings: Vec<(cake::Model, Vec<filling::Model>)> = |
| 182 | Cake::find().find_with_related(Filling).all(db).await?; |
| 183 | |
| 184 | println!("with loader: "); |
| 185 | let cakes: Vec<cake::Model> = Cake::find().all(db).await?; |
| 186 | let fillings: Vec<Vec<filling::Model>> = |
| 187 | cakes.load_many_to_many(Filling, CakeFilling, db).await?; |
| 188 | |
| 189 | println!(); |
| 190 | for (left, right) in cakes_with_fillings |
| 191 | .into_iter() |
| 192 | .zip(cakes.into_iter().zip(fillings.into_iter())) |
| 193 | { |
| 194 | println!("{left:?}\n"); |
| 195 | assert_eq!(left, right); |
| 196 | } |
| 197 | |
| 198 | print!("find fillings for cheese cake: "); |
| 199 | |
| 200 | let cheese = Cake::find_by_id(1).one(db).await?; |
| 201 | |
| 202 | if let Some(cheese) = cheese { |
| 203 | let fillings: Vec<filling::Model> = cheese.find_related(Filling).all(db).await?; |
| 204 | |
| 205 | println!(); |
| 206 | for ff in fillings.iter() { |
| 207 | println!("{ff:?}\n"); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | print!("find cakes for lemon: "); |
| 212 | |
| 213 | let lemon = Filling::find_by_id(2).one(db).await?; |
| 214 | |
| 215 | if let Some(lemon) = lemon { |
| 216 | let cakes: Vec<cake::Model> = lemon.find_related(Cake).all(db).await?; |
| 217 | |
| 218 | println!(); |
| 219 | for cc in cakes.iter() { |
| 220 | println!("{cc:?}\n"); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | Ok(()) |
| 225 | } |
| 226 | |
| 227 | async fn all_about_select_json(db: &DbConn) -> Result<(), DbErr> { |
| 228 | find_all_json(db).await?; |
no test coverage detected