• 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: indexing non-sorted arrays in EOs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: indexing non-sorted arrays in EOs


  • Subject: Re: indexing non-sorted arrays in EOs
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 23 Apr 2008 21:18:33 -0700


On Apr 23, 2008, at 8:02 PM, Jeff Schmitz wrote:

As I get into full swing of using EO's, I'm seeing one place that I know is going to bite me, and that is indexing into the array returned by the parameterless function that returns "many" relationships and assuming a certain order.

Don't. The order is undefined. It is really a set (unordered collection), not a vector. That is just the way it is.




I'd almost rather not even have that function, at least by default, so that it would force me to always either qualify or sort the results. e.g.

Doing this (assuming the array is sorted appropriately for winIndex:
WinAnalysis currWA = currGame.winAnalyses().objectAtIndex(winIndex);

Very dodgy. Expect painful debugging.


Instead of this:
   EOQualifier winQual = WinAnalysis.PLACE.eq(winIndex + 1);
    WinAnalysis currWA = currGame.winAnalyses(winQual).lastObject();

Or am I missing something? I'm just really scared this is going to bite me, and cost me LOTS of debugging time.

Usually you don't care about position within a to-many. If you do, you can very carefully carry around a sorted version. BUT it can be very tricky to keep this in sync so I do no recommend it. You could also sort / search / qualify everywhere you use it, but that is fragile and prone to being forgotten. Your best bet might be to make an API and use that in your processing. For example, add this to Game:



public WinAnalysis analysisAtPlace(int place) { EOQualifier winQual = WinAnalysis.PLACE.eq(place); return (WinAnalysis)winAnalyses(winQual).lastObject(); }

Then you don't need to worry about 0 based vs 1 based, just use aGame.analysisAtPlace(3); or maybe a better name is aGame.analysisOfRound(3);

Hide the implementation.  Code to the interface.

Chuck

--

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


  • Follow-Ups:
    • Re: indexing non-sorted arrays in EOs
      • From: Jeff Schmitz <email@hidden>
    • Re: indexing non-sorted arrays in EOs
      • From: Anjo Krank <email@hidden>
References: 
 >indexing non-sorted arrays in EOs (From: Jeff Schmitz <email@hidden>)

  • Prev by Date: Getting all Session Objects From Application
  • Next by Date: Re: Getting all Session Objects From Application
  • Previous by thread: indexing non-sorted arrays in EOs
  • Next by thread: Re: indexing non-sorted arrays in EOs
  • Index(es):
    • Date
    • Thread