Just a coder
Just a coder

Reputation: 16690

How to filter by Array in Vapor 4?

I can do a filter in Vapor 4 like this

Category.query(on: req.db)
   .filter(\.$description ~~ searchTags)

description here is a String. And it will match description to any of the strings in the searchTags array.

But what if description was also an array? Is there a way to match all the values in descriptionArray to the searchTags array?

Upvotes: 3

Views: 381

Answers (1)

Tommy Sadiq Hinrichsen
Tommy Sadiq Hinrichsen

Reputation: 804

If description was an array, then it should be made into an array of child objects, this way you can search for using a simple filter on description and parent id.

Upvotes: 1

Related Questions