Re: Sorting objects on attributes of related objects
Re: Sorting objects on attributes of related objects
- Subject: Re: Sorting objects on attributes of related objects
- From: Zak Burke <email@hidden>
- Date: Thu, 14 Sep 2006 10:46:18 -0400
Matt Kime wrote on 9/13/06 12:38 PM:
> Does sortArrayUsingKeyOrderArray support sorting based on the
> attributes of a related object? Or do I need to make sense of
> NSComparator? (anyone know of any good examples?)
For the record, here is a simple NSComparator example that sorts Person
objects by their nameFirst property:
public static NSComparator nameFirstComparator()
{
return (new NSComparator() {
public int compare(Object o1, Object o2) {
return ((Person)
o1).nameFirst().compareToIgnoreCase(((Person) o2).nameFirst());
}
});
}
If you wanted to sort by a related field (say you have Person <-> User
and User has a lastLogin field), you could use this:
public static NSComparator lastLoginComparator()
{
return (new NSComparator() {
public int compare(Object o1, Object o2) {
return ((Person)
o1).user().lastLogin().compareToIgnoreCase(((Person)
o2).user().lastLogin());
}
});
}
Cheers,
zak.
_______________________________________________
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