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

Support for @sum on relationship in NSPredicate #30

Closed
darronschall opened this issue Sep 24, 2013 · 2 comments
Closed

Support for @sum on relationship in NSPredicate #30

darronschall opened this issue Sep 24, 2013 · 2 comments
Assignees

Comments

@darronschall
Copy link

The collection operators used on relationships within NSPredicate are not currently working. I am trying to use a sum operation but am getting an error. This works in my existing Magical Record / Core Data application, but fails when I switch to EncryptedStore.

I'll describe my problem in terms of the FailedBankCD data model. Perform the following changes:

  1. Add a new FailedBankCustomer entity with a 'balance' Integer 32
  2. Create a to-many relationship on FailedBankInfo: 'customers' to FailedBankCustomer
// Find only the failed banks where the total balance across all customers > 100
NSPredicate *totalBalancePredicate = [NSPredicate predicateWithFormat:@"customers.@sum.balance > 100"];

[FailedBankInfo MR_fetchAllSortedBy:@"name" ascending:YES withPredicate:totalBalancePredicate groupBy:nil delegate:self];

The follow is the error I'm running into:

+[MagicalRecord(ErrorHandling) defaultErrorHandler:](0x2ec308) Error: no such column: customers.@sum.balance

The following is the generated query that triggers the above error:

SELECT FailedBankInfo.ID FROM FailedBankInfo JOIN FailedBankCustomer AS [customers] ON FailedBankInfo.customers_id = [customers].ID WHERE ([customers.@sum].balance > ?) ORDER BY FailedBankInfo.name ASC;
@ghost ghost assigned gavin-black Oct 2, 2013
@gavin-black
Copy link
Member

Was able to recreate the issue, thanks for the sample code. Assigning it to myself, but not sure when I'll have free time to get to it.

gavin-black added a commit that referenced this issue Feb 12, 2014
@gavin-black
Copy link
Member

This should be fixed now by commit 4ee23af, at least for the simpler comparison cases (i.e. foo.@sum.bar > faz and @sum.bar > faz). Closing this issue, but let me know if you encounter any more cases where the sum predicate is broken. Thanks again for finding this issue.

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

No branches or pull requests

2 participants