Skip to content

Searching for items with tags #1131

Answered by groue
ethankay asked this question in Q&A
Jan 8, 2022 · 1 comments · 6 replies
Discussion options

You must be logged in to vote

Hello @ethankay,

In order to solve this puzzle, you can take inspiration from the joining(required:) example:

// Fetch books by French authors
let request = Book.joining(required: Book.author.filter(Column("country") == "France"))

In your case, you want to fetch words that are joined to tag "foo", but also to tag "bar", and to tag "baz", etc:

// Fetch words with tags "foo", "bar", and "bar"
let request = Word
    .joining(required: ... "foo")
    .joining(required: ... "bar")
    .joining(required: ... "baz")

This gives:

extension Word {
    // Association to the tag named `tag`
    static func tag(named tag: String) -> HasOneAssociation<Word, TagToWord> {
        // Prefer hasOne to hasM…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@ethankay
Comment options

@groue
Comment options

@groue
Comment options

@groue
Comment options

@ethankay
Comment options

Answer selected by groue
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