test the control case
(self, connection)
| 168 | session.flush() |
| 169 | |
| 170 | def test_noorm(self, connection): |
| 171 | """test the control case""" |
| 172 | |
| 173 | tests, options, categories = ( |
| 174 | self.tables.tests, |
| 175 | self.tables.options, |
| 176 | self.tables.categories, |
| 177 | ) |
| 178 | |
| 179 | # I want to display a list of tests owned by owner 1 |
| 180 | # if someoption is false or they haven't specified it yet (null) |
| 181 | # but not if they set it to true (example someoption is for hiding) |
| 182 | |
| 183 | # desired output for owner 1 |
| 184 | # test_id, cat_name |
| 185 | # 1 'Some Category' |
| 186 | # 3 " |
| 187 | |
| 188 | # not orm style correct query |
| 189 | print("Obtaining correct results without orm") |
| 190 | result = connection.execute( |
| 191 | sa.select(tests.c.id, categories.c.name) |
| 192 | .where( |
| 193 | sa.and_( |
| 194 | tests.c.owner_id == 1, |
| 195 | sa.or_( |
| 196 | options.c.someoption == None, # noqa |
| 197 | options.c.someoption == False, |
| 198 | ), |
| 199 | ) |
| 200 | ) |
| 201 | .order_by(tests.c.id) |
| 202 | .select_from( |
| 203 | tests.join(categories).outerjoin( |
| 204 | options, |
| 205 | sa.and_( |
| 206 | tests.c.id == options.c.test_id, |
| 207 | tests.c.owner_id == options.c.owner_id, |
| 208 | ), |
| 209 | ) |
| 210 | ) |
| 211 | ).fetchall() |
| 212 | eq_(result, [(1, "Some Category"), (3, "Some Category")]) |
| 213 | |
| 214 | def test_withoutjoinedload(self): |
| 215 | Thing, tests, options = ( |