Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where expression for FieldRelationshipToMany properties #473

Open
itShouldWork opened this issue Mar 23, 2023 · 1 comment
Open

where expression for FieldRelationshipToMany properties #473

itShouldWork opened this issue Mar 23, 2023 · 1 comment

Comments

@itShouldWork
Copy link

Hi! There is a problem with .where expressions in case you are trying to filter toMany Relationship properties. In my code example I want to fetch all Master's which contains Pet with name Spot.

Code example:

final class Master: CoreStoreObject {
    @Field.Relationship("pets")
    var pets: [Pet]
}
final class Pet: CoreStoreObject {
    @Field.Stored("name")
    var name: String = ""
    @Field.Relationship("master", inverse: \.$pets)
    var master: Master?
}

func fetch() {
    let itWorks = From<Pet>()
        .where((\.$master ~ \.$pets ~ \.$name).any() == "Spot") // It doesn't reproduce any compiler errors

    let itDoesntWork = From<Master>()
        .where((\.$pets ~ \.$name).any() == "Spot") // Compiler errors: 
    // Operator function '~' requires that '[Pet]' conform to 'FieldRelationshipToOneType'
    // Operator function '~' requires that 'FieldContainer<Pet>.Stored<String>' conform to 'ToManyRelationshipKeyPathStringConvertible'
}

Seems like a common case, so maybe I'm doing something wrong?

@JohnEstropia
Copy link
Owner

Thanks, it looks like a missing overload for the ~ operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants