• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Comparing attributes in related objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing attributes in related objects


  • Subject: Re: Comparing attributes in related objects
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 29 Aug 2007 13:31:07 -0700

Replying to the correct list. CCing WOLips (where originally posted), but please do not reply there.

Other options:

- there is no problem adding a lastUsedCreditCard() relationship that has one of the creditCards() objects in it. Just make sure to update this if you delete the lastUsedCreditCard(). Having this relationship allows you to construct fetchspecs on this criteria.

- Pierre Bernard's BestRelationshipMatchesQualifier might also work for this:
Qualifier to find objects where a related object with a given attribute as close as possible to a specified value
* matches a provided qualifier.

I have not used it though. Find it at http://www.bernard-web.com/ pierre/webobjects/code.html under Qualifier Additions. Lots of other very useful qualifiers there too.



Chuck


On Aug 29, 2007, at 1:15 PM, Ken Anderson wrote:

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



--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
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


  • Prev by Date: Re: NiftyCube in WO (maybe off-topic)
  • Next by Date: WOHyperlink pass arguments.
  • Previous by thread: Re: NiftyCube in WO (maybe off-topic)
  • Next by thread: WOHyperlink pass arguments.
  • Index(es):
    • Date
    • Thread