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

Optional One to Many relationship support #5

Closed
omiz opened this issue Apr 7, 2021 · 2 comments
Closed

Optional One to Many relationship support #5

omiz opened this issue Apr 7, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@omiz
Copy link
Contributor

omiz commented Apr 7, 2021

Is it possible to have a predicate for an optional one to Many relationship?

An example of what I'm trying to achieve is this
I want to get the objects without a relation

class NoteGroup: NSManagedObject {
    var notes: [Note]?
}

class Note: NSManagedObject {
    var group: NoteGroup?
}

let predicate = (\Note.group) == nil

unfortunately that currently doesn't work since NoteGroup is not a primitive type so it can't be passed as a fetch where condition

@omiz omiz changed the title Optional One to One relationship support Optional One to Many relationship support Apr 7, 2021
@ftchirou ftchirou self-assigned this Apr 12, 2021
@ftchirou ftchirou added enhancement New feature or request good first issue Good for newcomers labels Apr 12, 2021
@ftchirou
Copy link
Owner

Hey! Thanks for opening this issue. I'll look into adding support for something like this. Will update this issue with my findings.

@ftchirou
Copy link
Owner

ftchirou commented Apr 18, 2021

Fixed in 1.4.0.

You should be able to write the following once you update to 1.4.0 @omiz.

let predicate: Predicate<Note> = \Note.group == nil

If you store your predicate in a variable, you may need to explicitly provide the type (as in the example above) to help the compiler disambiguate between \Note.group == nil // => Predicate<Note> and \Note.group == nil // => Bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants