@@ -2796,3 +2796,50 @@ 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+ defer {
2820+ print ( sqlQueries. joined ( separator: " \n " ) )
2821+ }
2822+ try dbQueue. write { db in
2823+ try db. create ( table: " food " ) { t in
2824+ t. column ( " id " , . blob) . primaryKey ( )
2825+ t. column ( " name " , . text)
2826+ t. column ( " foodId " , . text) . unique ( )
2827+ }
2828+
2829+ try db. create ( table: " serving " ) { t in
2830+ t. column ( " id " , . blob) . primaryKey ( )
2831+ t. column ( " description " , . text)
2832+ t. column ( " foodId " , . text) . references ( " food " , column: " foodId " )
2833+ }
2834+
2835+ try db. create ( virtualTable: " food_fts " , using: FTS5 ( ) ) { t in
2836+ t. synchronize ( withTable: " food " )
2837+ t. column ( " name " )
2838+ }
2839+
2840+ try Food ( id: UUID ( ) , name: " Apple " , foodId: " apple " ) . save ( db)
2841+ try Serving ( id: UUID ( ) , description: " Apple " , foodId: " apple " ) . save ( db)
2842+ }
2843+ }
2844+ }
2845+ #endif
0 commit comments