Prisma/Planetscale issue
Hello, why can't I define an array of strings in prisma using mysql and planetscale?
Edit: I understand the error message and "why" it doesn't work but I can't find a solution to the issue.
6 Replies
Because Planetscale uses Vitess which is based on MySQL which doesn't have arrays like PostgreSQL.
And how would I go about to handle a field that can have multiple inputs?
Would a good solution be to Type it as a JSON and then store it as:
{1: "url", 2:"url2"}?
Usually a bad idea. Normalize your data unless you have a reason not to.
The problem is that I need something in the form of:
model Org {
...
allowedDomains: ["Domain 1", "Domain 2"]
}
Do I really have to make a new model and then do a relation to this Org model where I allow multiple inputs?
That's the way it's usually done.
Of course can use JSON or blob or w/e - but an extra table makes it easier to query the data.
The other option would be to use a special separator and use a LIKE query(i.e.
WHERE allowedDomains LIKE 'domain.com|%' OR allowedDomains LIKE '%|domain.com|%' allowedDomains LIKE '%|domain.com'
), but that's prone to errors and, like Christoph said, the way it is normally done is using a separate model and table