So I am not sure if I am doing something wrong or if this is an issue. When I generate a scaffold for one of my types called a farm see schema:
model Farm {
createdAt DateTime @default(now())
description String?
farmers String?
founded Int?
id Int @id @default(autoincrement())
laborSource String?
name String @unique
otherCertifications String
partnerSince Int?
safetyCertifications String
size String?
sustainabilityPractices String
updatedAt DateTime @default(now())
url String?
city String
lat Float?
lng Float?
state String
street String
zip Int
logo String
images String[]
Inventories Inventory[] @relation(references: [id])
}
The resulting SDL does acknowledge the string array:
export const schema = gql`
type Farm {
createdAt: DateTime!
description: String
farmers: String
founded: Int
id: Int!
laborSource: String
name: String!
otherCertifications: String!
partnerSince: Int
safetyCertifications: String!
size: String
sustainabilityPractices: String!
updatedAt: DateTime!
url: String
city: String!
lat: Float
lng: Float
state: String!
street: String!
zip: Int!
logo: String!
images: String // <----- This should be an array
Inventories: Inventory
}
...
I think the reason is that SQLite doesn’t natively support scalar lists:
Here’s the relevant bit:
Note : Scalar lists (arrays) are only supported in the data model if your database natively supports them. Currently, scalar lists are therefore only supported when using PostgreSQL (since MySQL and SQLite don’t natively support scalar lists).
Since Redwood apps use SQLite by default, I’m guessing we based our sdl generator on what SQLite could do. So I don’t think what you’re seeing is a bug per se (and you’re not doing anything wrong either!), but the interesting point you bring up is having the sdl generator be more database aware.
Fair point missed that in the docs. But if you will also notice it seems to be happening on related models too. Inventories is a one to many relationship shouldn’t that be an array of the model in the SDL as well?
Honestly, when I wrote the SDL generator I didn’t even realize this was valid syntax! I only ever saw array syntax in the Prisma docs used when specifying a relationship to another model, like User[]. Searching their docs for that usage:
So yeah, this would require a code change.
However Inventories should have been generated as an array…that may be a bug.
In the meantime you’ll need to manually tweak those generated SDLs, sorry about that!
No worries at all, really small stuff here, loving Redwood so far. You want me to take the github issue down or adjust it to address the model relation sdl generation?