@@ -2796,3 +2796,47 @@ extension MutablePersistableRecordTests {
27962796 } catch DatabaseError . SQLITE_MISUSE { }
27972797 }
27982798}
2799+
2800+ #if SQLITE_ENABLE_FTS5
2801+ class Issue1820Tests : GRDBTestCase {
2802+ // Regression test for https://github.com/groue/GRDB.swift/issues/1820
2803+ func testIssue1820( ) throws {
2804+ struct Serving : Codable , FetchableRecord , PersistableRecord {
2805+ let id : UUID
2806+ var description : String
2807+ var foodId : String
2808+
2809+ static let author = hasOne ( Food . self)
2810+ }
2811+
2812+ struct Food : Codable , FetchableRecord , PersistableRecord {
2813+ let id : UUID
2814+ var name : String
2815+ var foodId : String
2816+ }
2817+
2818+ let dbQueue = try makeDatabaseQueue ( )
2819+ try dbQueue. write { db in
2820+ try db. create ( table: " food " ) { t in
2821+ t. column ( " id " , . blob) . primaryKey ( )
2822+ t. column ( " name " , . text)
2823+ t. column ( " foodId " , . text) . unique ( )
2824+ }
2825+
2826+ try db. create ( table: " serving " ) { t in
2827+ t. column ( " id " , . blob) . primaryKey ( )
2828+ t. column ( " description " , . text)
2829+ t. column ( " foodId " , . text) . references ( " food " , column: " foodId " )
2830+ }
2831+
2832+ try db. create ( virtualTable: " food_fts " , using: FTS5 ( ) ) { t in
2833+ t. synchronize ( withTable: " food " )
2834+ t. column ( " name " )
2835+ }
2836+
2837+ try Food ( id: UUID ( ) , name: " Apple " , foodId: " apple " ) . save ( db)
2838+ try Serving ( id: UUID ( ) , description: " Apple " , foodId: " apple " ) . save ( db)
2839+ }
2840+ }
2841+ }
2842+ #endif
0 commit comments