Re: Sort problem
Re: Sort problem
- Subject: Re: Sort problem
- From: David Holt <email@hidden>
- Date: Fri, 15 Apr 2005 14:36:02 -0700
Oh dear, I am still banging away at this problem. I think I have figured out where the problem lies, but I don't know how to solve it. >From the code below, you'll see that I can find the last post by sorting on the timestamp of posts in a topic and taking the last object. What I was stupidly doing was then using the lastpost as the key to sort the topics, but I don't specify what attribute of the lastpost I am sorting on. I want to sort on lastpost.timestamp. Can someone please give me a hint how to do this? Thanks,
David
--
<x-tad-smaller>"Insanity is expecting different results from repeating the same
action." -- Anonymous</x-tad-smaller>
On 10 Mar 2005, at 1:48 PM, David Holt wrote:
Just in case some code would help:
The lastPost method:
public Post lastPost()
{
NSMutableArray thePosts = (NSMutableArray) "posts");
// sort the posts by timestamp
EOSortOrdering timeOrdering = EOSortOrdering.sortOrderingWithKey("timestamp", EOSortOrdering.CompareAscending);
NSMutableArray ordering = new NSMutableArray();
ordering.addObject(timeOrdering);
EOSortOrdering.sortArrayUsingKeyOrderArray(thePosts,ordering);
return (Post) thePosts.lastObject();
}
topics sorted by timestamp:
public NSMutableArray theSortedTopics()
{
NSMutableArray theTopics = (NSMutableArray) "topics");
// sort the topics by lastPost
EOSortOrdering timeOrdering = EOSortOrdering.sortOrderingWithKey("lastPost", EOSortOrdering.CompareDescending);
NSMutableArray ordering = new NSMutableArray();
ordering.addObject(timeOrdering);
EOSortOrdering.sortArrayUsingKeyOrderArray(theTopics,ordering);
return (NSMutableArray) theTopics;
}
On 10 Mar 2005, at 9:23 AM, David Holt wrote:
Hello everyone,
I have a very simple forum with forum>topics>posts. In my Topic EO I have a method to find the lastPost by sorting the posts in ascending order and then returning the last object in the array.
In my Forum EO I have a method to sort topics descending on the lastPost. This works fine except in the case that there is an attachment to the last post. If there is an attachment (MediumBlob in mysql) the last post shows up fine in the display on the forum page, but the topic sort does not seem to take it into consideration (the topic that includes the attachment doesn't display at the top). Does anyone have any idea why this might be happening?
David
--
When you sit with a nice girl for two hours you think that it is only a minute. But when you sit on a hot stove for a minute you think it's two hours. That's relativity.
<x-tad-smaller>
Albert Einstein
from Sunbeams: http://www.thesunmagazine.org</x-tad-smaller>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden