Hi there,

On 10/02/2006, at 10:00 AM, Owen McKerrow wrote:

Objective : To get the full list of External Authors active names.

DB setup :
Person <- ->> PersonName (so a person can have many names thus allowing for name changes, while keeping the old name for historic time snap shots)

Right. i.e., inactive names are rarely needed which makes the following a regular waste of time anyway.

So in my Person class I have a function for getting the currently active name :

public PersonName activeName()
{
        int i;
        PersonName theName= null;
        for (i=0;i<personNames().count();i++) {
                PersonName temp = (PersonName)personNames().objectAtIndex(i);
                if ( temp.active().intValue() == 1 ) {
                        theName = temp;
                        break;
                }
        }
        return theName;
}

Is there an easier/quicker way to do this?

Don't fetch objects you'll rarely use ;-) i.e., filter out the inactive ones during the fetch...

Should I have a second to-one relationship which is for the active name?

Sounds like a much better idea. That way the 'active' class attribute goes away and you instead have a foreign key in Person. Clean. Easy.

I should note that there about 5 people in the DB which actually have more than 1 name, so in 98ish% of cases this is returns the first object.

Hence the rarity of using the extra names.

While time's relevant, I'd also suggest using primitives in for-loops (via a single object call at the beginning) instead of regular method calls per iteration. i.e.,

        for (int i = 0, count = personNames.count(); i < count; i++ ) { }

with regards,
--

Lachlan Deck

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to