Ideally I wanted tags to be an array of string but...
# prisma-whats-new
w
Ideally I wanted tags to be an array of string but it seems this is seems filtering scalars is not possible currently ?
a
You should be able to do
Copy code
filter: { tags_every: { key_in: ["tag1", "tag2"] } }
It's not a scalar list, it's a relation, so the key_in field in generated. You can also try this out in the Playground, it has intellisense!
w
thanks, thatโ€™s very helpful!
๐Ÿ˜Ž 1
If I understand this right, this condition means every tag should be in the array
["tag1", "tag2"]
so I would get items that have tag1 or tag2.
How would I get items that have tag1 and tag2 ?
Something like this ?
Copy code
filter: {AND: [{tags_every: {key_in: ["tag1"]}}, {tags_every: {key_in: ["tag2"]}}]}
z
What if you always passed tags as a string separated by commas? would that help
a
no, then you need to use
some
, you can do:
Copy code
filter: { AND: [
   { tags_some: { key: "tag1"} },
   { tags_some: { key: "tag2"} }
]}
@zach in my first sample, you can pass in the array as a variable:
Copy code
filter: { tags_every: { key_in: $tags } }
w
@agartha oh of course, thanks ๐Ÿ™‚
๐Ÿ˜Ž 1
a
every tag can't be "tag1" and "tag2" at the same time ๐Ÿ˜‰
๐Ÿ˜‚ 1
w
Is it possible to have my
Tag
type have their key as their id ?
I find it a bit strange that my items have an array of ids as tags
My use case is I want to add tags as strings when tagging an item
If I understand the doc example right, if multiple items have the same tag (key string), it would create a different tag (same key but different id) for each item
a
I'm not sure which example you're talking about, but references are always by ID. You can make the key field unique though.
w
Ok, thanks! (Iโ€™m referring to https://www.graph.cool/docs/reference/simple-api/filtering-by-field-xookaexai0/ which describes a one item to many tags relation)