Strategy to handle nested records #1386
-
|
Hello! struct A: PersistableRecord, FetchableRecord, TableRecord {
let id: String
var b: B
}
struct B: PersistableRecord, FetchableRecord, TableRecord {
let id: String
let value: Int
}So |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hello @tgrapperon, I don't doubt that the
But And Using unfit protocols will create mismatches and oddities that are the signs that the application is fighting the framework. All in all, the For further information, and details about the setup expected by GRDB, see the related sections in the Recommended Practices for Designing Record Types guide: I'm not saying this is ideal, and there is certainly room for improvements. Previous issues shed some light on the problems to solve: #1322, #1354. |
Beta Was this translation helpful? Give feedback.
Hello @tgrapperon,
I don't doubt that the
Atype is the one you want your app to use. It's the "canonical" model. My advice is to not make it use unfit protocols.Acan implementFetchableRecord(please refer to its documentation, as well as the Associations guide).But
Ais not a "table record", becauseTableRecordis all about single tables. For example, whenTableRecordgenerates SQL forA.fetchAll(db), it does not embed the Bs.And
Ais not a "persistable record" either. If you think about it, persisting a composite object such asAsupports multiple strategies. For example, what deleting anAshould do? Maybe your app wants to delete rows in both the A and B tables. Maybe some other …