Re: CoreData: Fetching object with maximum of property
Re: CoreData: Fetching object with maximum of property
- Subject: Re: CoreData: Fetching object with maximum of property
- From: Negm-Awad Amin <email@hidden>
- Date: Tue, 7 Oct 2008 15:18:14 +0200
Am Di,07.10.2008 um 15:12 schrieb Frank Illenberger:
Hello Negm-Awad,
thanks for helping.
Nicht dafür!
The idea with the fetch limit and the descending order solves my
problem as I am using a SQLite store.
Sonst hättest du auch nicht das Problem. ;-)
Liebe Grüße
Amin
Cheers
Frank
On Oct 7, 2008, at 2:59 PM, Negm-Awad Amin wrote:
In contrast to Bill I think, that this is not possible with
predicates. Why?
You want to get the maximum value of an attribute. Obviously this
task includes the knowledge of all values stored in that attribute.
So if Core Data should do that, there are two approaches:
a) Reading all attributes and compare it. This is, what you didn't
want to do.
b) Delegate this task to the SQL store.
The second one is the solution. But predicates filters the
attributes. They do not really aggregate them, even there are some
aggregates available. These aggregates filters the source entity by
resolving a relationship, but not by aggregating a min or max value.
*If there is a solution using predicates, I'm highly interested in
it.*
However, there is another solution, that should work:
When you have an entity you can fetch the instances of the entity.
And you can sort them by using a sort descriptor. And you can set a
fetch limit. So simply create a fetch request, set the sort
descriptor's key to the attribute and the sort descriptor's order
to descending. Set the fetch limit to 1. Executing this fetch will
lead to the instance with the value for that attribute.
AFAIK this sort descriptors and limits are passed to the sql store.
So the SQL engine will do that work. (Anyway the SQL engine of
course has to read every value.)
-bd-
http://bill.dudney.net/roller/objc
On Oct 7, 2008, at 3:49 AM, Frank Illenberger wrote:
Hi everybody,
does anybody know if CoreData under Leopard offers a way to
fetch the object of an entity which the maximum of a certain
property value, but without having to fetch all objects into
memory?
Cheers
Frank
Amin Negm-Awad
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden