| 96 | |
| 97 | #[sea_orm_macros::test] |
| 98 | pub async fn exists_with_complex_query() { |
| 99 | let ctx = TestContext::new("exists_with_complex_query").await; |
| 100 | create_tables(&ctx.db).await.unwrap(); |
| 101 | |
| 102 | let _bakery1 = bakery::ActiveModel { |
| 103 | name: Set("SeaSide Bakery".to_owned()), |
| 104 | profit_margin: Set(10.4), |
| 105 | ..Default::default() |
| 106 | } |
| 107 | .save(&ctx.db) |
| 108 | .await |
| 109 | .expect("could not insert bakery"); |
| 110 | |
| 111 | let _bakery2 = bakery::ActiveModel { |
| 112 | name: Set("Top Bakery".to_owned()), |
| 113 | profit_margin: Set(15.0), |
| 114 | ..Default::default() |
| 115 | } |
| 116 | .save(&ctx.db) |
| 117 | .await |
| 118 | .expect("could not insert bakery"); |
| 119 | |
| 120 | let _bakery3 = bakery::ActiveModel { |
| 121 | name: Set("Low Profit Bakery".to_owned()), |
| 122 | profit_margin: Set(5.0), |
| 123 | ..Default::default() |
| 124 | } |
| 125 | .save(&ctx.db) |
| 126 | .await |
| 127 | .expect("could not insert bakery"); |
| 128 | |
| 129 | // Test with complex filter - exists bakery with profit margin > 12 |
| 130 | let exists = Bakery::find() |
| 131 | .filter(bakery::Column::ProfitMargin.gt(12.0)) |
| 132 | .exists(&ctx.db) |
| 133 | .await |
| 134 | .unwrap(); |
| 135 | assert_eq!(exists, true); |
| 136 | |
| 137 | // Test with complex filter - exists bakery with profit margin > 20 |
| 138 | let exists = Bakery::find() |
| 139 | .filter(bakery::Column::ProfitMargin.gt(20.0)) |
| 140 | .exists(&ctx.db) |
| 141 | .await |
| 142 | .unwrap(); |
| 143 | assert_eq!(exists, false); |
| 144 | |
| 145 | ctx.delete().await; |
| 146 | } |
| 147 | |
| 148 | #[sea_orm_macros::test] |
| 149 | pub async fn exists_with_joins() { |