Re: fetch request with compound predicate doesn't sort properly
Re: fetch request with compound predicate doesn't sort properly
- Subject: Re: fetch request with compound predicate doesn't sort properly
- From: Greg Herlihy <email@hidden>
- Date: Wed, 15 Mar 2006 20:18:58 -0800
- Thread-topic: fetch request with compound predicate doesn't sort properly
The object model always returns the same NSFetchRequest object for a
template name (unless the request uses substitution variables). So it would
make sense that any sort descriptors used for previous requests would
³stick² with the request it¹s the same object after all.
It¹s also less clear why making a copy of the NSFetchRequest object would
clear its sort descriptors I would expect them to be copied as well.
Instead of copying the request, I would have the program set the sort
descriptors to an empty array for any request whose results do not need to
be sorted. At any rate, I think that the state of the NSFetchRequest object
returned by the object model (particularly the state of its sort
descriptors) is the most likely cause of the problem (which also explains
why requests created programmatically sort correctly, because the same
request object is not being re-used for each set of objects fetched.)
At this point, it¹s not clear what in particular would be wrong with the
state of the NSFetchRequest object or how it got into that state.
Nonetheless, that seems that most promising theory to me.
Greg
On 3/14/06 4:00 PM, "Ken Victor" <email@hidden> wrote:
> At 3:51 PM -0800 3/14/06, Greg Herlihy wrote:
>> Is there a reason for making a copy of the NSFetchRequest? And have you
>> tested without making this copy:
>>
>> NSFetchRequest* request = [objectModel fetchRequestTemplateForName: fn];
>
> the same problem exists whether or not i make the copy. i make the copy
> because i use the same fetch request with different sort descriptors at
> various parts of my app. i discovered empiracally that setting the sort
> descriptors on a request retrieved from the model "stuck" with the request
> the next time i retreived it from the model. i didn't quite understand why
> this was so, but figured the easiest solution was simply to use a copy and
> then "attach" the appropriate sort descriptors as needed.
>
> ken
>
>
>>
>>
>> Greg
>>
>> On 3/14/06 3:30 PM, "Ken Victor" <email@hidden> wrote:
>>>>> > NSFetchRequest* request = [[[objectModel
>>>>> > fetchRequestTemplateForName: fn] copy] autorelease];
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden