Open abbasmousavi opened 3 years ago
I suspect you'll need .field("teams", .json)
if you want it to work, but what errors are you getting?
If I use .field("teams", .json)
it ends up on line 37 ofpostgres-nio/Sources/PostgresNIO/Data/PostgresData+Array.swift
with this fatal error:
fatalError("No array type for \(elementType)")
Fatal error: No array type for JSONB[]
Is that after the save or before save? It's it's after the save, what does the JSON look like in the database?
It is before save. It does not save to database.
@0xTim if I wrap it in a class like
class TeamWrapper: Codable {
let team: [[Person]]
}
It will work without any problem, but the unwrapped double array causes the problem.
Describe the bug
saving and retrieving an array of arrays of a custom type is not possible.
To Reproduce
I have a person struct like this
and in my model I have a field like this
Expected behavior
I want to be able to save it in my Postgres database. I have used
.field("teams", .array(of: .json))
and.field("teams", .json)
and.field("teams", .array(of:.array(of: .json)))
as the field definition in my migration but none of them work.
Environment