0
votes

I have a Core Data Model as follows 1. Task Entity: Attributes objDueDate, Relationship objRecurrence etc. 2. Recurrence Entity: Attributes objEndDate, objStartDate, Relationship tasks, etc.

Task has a many-to-one relationship to Recurrence. Recurrence has an inverse one-to-many relationship with Task. I wish to query the last task of a recurrence sequence by writing an NSFetchRequest predicate as follows

NSPredicate* lobjPredicate = [NSPredicate predicateWithFormat:"objDueDate == [email protected]"]

This fails with an error saying

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to generate SQL for predicate (objDueDate == max:(objRecurrence.tasks.objDueDate))

Can anyone please explain why does this not work?

Thanks in advance....

Explanation of Scenario:

I wish to display tasks sorted by Categories. I also make it compulsory that if you make a task as recurring, all tasks in the recurrence will share the same category. Now there are two sets of tasks: one with recurrence and one without recurrence. Now out of a recurrence sequence (lets say A) I want only one task to be presented to the user. If all tasks in the sequence have been marked done then I wish to present the last done task to the user. If some tasks in the sequence have been marked as done then I wish to present the first Incomplete task to the user.

How can I solve the scenario???

2

2 Answers

0
votes

I have an idea for a simplification that would avoid this error: fetch the tasks of one recurrence sorted by dueDate and set the fetchLimit to one.

0
votes

I'm not sure why you are using both objRecurrence and tasks in the predicate. If they are the inverse of each other then you just need to walk through the Task Entity relationship (objRecurrence). That might solve your problem.