@@ -80,10 +80,11 @@ class CountryRepository(SQLAlchemySyncRepository[UUIDCountry]):
80
80
france = UUIDCountry (name = "France" )
81
81
db_session .add (usa )
82
82
db_session .add (france )
83
+ db_session .flush () # Ensure countries are in session before creating states
83
84
84
- california = UUIDState (name = "California" , country = usa )
85
- oregon = UUIDState (name = "Oregon" , country = usa )
86
- ile_de_france = UUIDState (name = "Île-de-France" , country = france )
85
+ california = UUIDState (name = "California" , country_id = usa . id )
86
+ oregon = UUIDState (name = "Oregon" , country_id = usa . id )
87
+ ile_de_france = UUIDState (name = "Île-de-France" , country_id = france . id )
87
88
88
89
repo = USStateRepository (session = db_session )
89
90
repo .add (california )
@@ -202,10 +203,11 @@ class CountryRepository(SQLAlchemyAsyncRepository[BigIntCountry]):
202
203
france = BigIntCountry (name = "France" )
203
204
db_session .add (usa )
204
205
db_session .add (france )
206
+ await db_session .flush () # Ensure countries are in session before creating states
205
207
206
- california = BigIntState (name = "California" , country = usa )
207
- oregon = BigIntState (name = "Oregon" , country = usa )
208
- ile_de_france = BigIntState (name = "Île-de-France" , country = france )
208
+ california = BigIntState (name = "California" , country_id = usa . id )
209
+ oregon = BigIntState (name = "Oregon" , country_id = usa . id )
210
+ ile_de_france = BigIntState (name = "Île-de-France" , country_id = france . id )
209
211
210
212
repo = USStateRepository (session = db_session )
211
213
await repo .add (california )
@@ -323,10 +325,11 @@ class CountryRepository(SQLAlchemySyncRepository[UUIDCountryTest]):
323
325
france = UUIDCountryTest (name = "France" )
324
326
db_session .add (usa )
325
327
db_session .add (france )
328
+ db_session .flush () # Ensure countries are in session before creating states
326
329
327
- california = UUIDStateTest (name = "California" , country = usa )
328
- oregon = UUIDStateTest (name = "Oregon" , country = usa )
329
- ile_de_france = UUIDStateTest (name = "Île-de-France" , country = france )
330
+ california = UUIDStateTest (name = "California" , country_id = usa . id )
331
+ oregon = UUIDStateTest (name = "Oregon" , country_id = usa . id )
332
+ ile_de_france = UUIDStateTest (name = "Île-de-France" , country_id = france . id )
330
333
331
334
repo = USStateRepository (session = db_session )
332
335
repo .add (california )
@@ -421,10 +424,11 @@ class CountryRepository(SQLAlchemyAsyncRepository[BigIntCountryTest]):
421
424
france = BigIntCountryTest (name = "France" )
422
425
db_session .add (usa )
423
426
db_session .add (france )
427
+ await db_session .flush () # Ensure countries are in session before creating states
424
428
425
- california = BigIntStateTest (name = "California" , country = usa )
426
- oregon = BigIntStateTest (name = "Oregon" , country = usa )
427
- ile_de_france = BigIntStateTest (name = "Île-de-France" , country = france )
429
+ california = BigIntStateTest (name = "California" , country_id = usa . id )
430
+ oregon = BigIntStateTest (name = "Oregon" , country_id = usa . id )
431
+ ile_de_france = BigIntStateTest (name = "Île-de-France" , country_id = france . id )
428
432
429
433
repo = USStateRepository (session = db_session )
430
434
await repo .add (california )
0 commit comments