views:

158

answers:

1

I have an object in core data that has 2 fields: Name and Date. Each time a person checks in it saves their name and the time they did it.

Is there a way to get a list of all unique people with their last check in time using a predicate in core data?

Note: i do know that 2 tables would make it easier.

the sql for this would be

select 
    clientName
    , MAX(ModifiedDate) 
from
    Client
group by 
    clientName
+1  A: 

No not easily since Core Data is an object graph first. You could do it by grabbing a distinct set of the names and then querying for the max for each via a sort.

The best answer is to break it into two tables otherwise it is going to be computationally expensive each time you try and resolve this.

OR/M Layer

Don't think of it as an OR/M layer. Core Data is an object graph; full stop.

The fact that it happens to persist to a database structure as one of its persistence options is secondary.

The issue in your question is that you are trying to use an Object Graph as a database. In that situation I get to use a phase that is very frequently attributed to me:

"You're doing it wrong." :)

Marcus S. Zarra
That is what I thought. Nothing like another OR/M layer to make things easier :).
Aaron
I'd go even farther and say that if you think of Core Data as using tables, you're going to do it wrong. Entities look a lot like tables but thinking of them that way leads to inappropriate database-style thinking.
Tom Harrington