In this type of situation, I would just sort the array on lastUsed
date, and take the last object from the array:
In your customer class:
public NSArray lastUsedCreditCard() {
EOSortOrdering ordering = EOSortOrdering.sortOrderingwithKey
(CreditCard.LastUsedDate, EOSortOrdering.CompareAscending);
return EOSortOrdering.sortedArrayUsingKeyOrderArray
(this.creditCards(), new NSArray(ordering));
}
In code that wants the last credit card from a customer:
CreditCard lastUsedCard = customer.lastUsedCreditCard().lastObject();
Ken
On Aug 29, 2007, at 4:05 PM, Lachlan Scott wrote:
To meet a client requirement, we want to traverse the object graph
and compare attributes of related entities.
Specifically, we want to select a user's last-used credit card.
User has to-many relationship CreditCards to CreditCard.
CreditCard has a timestamp recording its last use. We wish to
compare the timestamps and select the last-used CreditCard.
So the credit cards are available through the relationship, and we
could fix this by spooging stuff into standard Java, or even
adding flags into the model; but these don't feel right, and we
imagine it is the sort of thing WO would provide a mechanism for.
Does anyone have any suggestions about which classes we might be
able to use, here?
Many thanks
Lachlan
--
Lachlan Scott
Senior Bloke
Run The Red (http://www.runthered.com)
Wellington, New Zealand
Wk: +64 (0)4 384 6880
Mb: +64 (0)21 824 244