Skip to content

List Filters Array Contains ? #2213

Answered by Isakdl
SemihYlmzz asked this question in Q&A
Discussion options

You must be logged in to vote

If the list is a relation field you are able to do that with the any method.

See: https://docs.serverpod.dev/concepts/database/filter#any
and how to setup a relation: https://docs.serverpod.dev/concepts/database/relations/one-to-many

Post.db.find(
      session,
      where: (table) => table.likerIDList.any((o) => o.id.equals(myId)),
);

However, if you have stored the list as a json blob then currently there is no built-in support to query for specific items within the json blob.

But you can always write a custom query using the unsafeQuery method.
https://docs.serverpod.dev/concepts/database/raw-access

For your use case the query could look something like this:
https://stackoverflow.com/…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Isakdl
Comment options

Answer selected by Isakdl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants