On May 8, 2009, at 1:30 PM, Chuck Hill wrote:

Hi Charles,

Welcome!


On May 7, 2009, at 5:20 PM, Charles Young wrote:

Hi

I'm sure I have a commonly seen issue:

I have a many to many relationship between tables SOURCE and DEST. This is implemented by a third table GLUE which contains the PKs of SOURCE and DEST as well as an integer property (order) that describes the order of DESTs with respect to SOURCE.

This might not be so common. A more common thing is to order them by an attribute of DEST.



I'd like to flatten the relationship such that I can call a method like:

source.dests() -> NSArray <Dest>

where the array is ordered by source.glue.order().

I've written a simple method that grabs source.glue(), sorts it on glue.order() and then iterates to extract dest, but I'm sure this issue has been solved many, many times before in a cleaner and more elegant manner.

I can't think of another way. You could encapsulate this in a generic method using Key-Value coding so that you only had to write it once.


If you are using Wonder, here's what I will usually do in this situation:

public NSArray<Dest> sortedDests() {
        NSArray<Glue> sortedGlues = glues(null,Glue.ORDER.ascs());
        return (NSArray<Dest>) sortedGlues.valueForKey(Glue.DEST);
}

Which, as Chuck suggests, can then be abstracted from the specific entities using KVC so you don't have to rewrite it for each many-to- many relationship. But it's not a lot of code anyway.




On a separate subject thanks to all for a very interesting and informative group. I've been lurking for some time and have been enjoying the various conversations.


:-)

Especially the goat herding threads, I bet. :-)

Are you coming to WOWODC?

Dave




Chuck


--
Chuck Hill             Senior Consultant / VP Development

Come to WOWODC'09 in San Fran this June!
http://www.wocommunity.org/wowodc09/

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

This email sent to webobje...@avendasora.com



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

This email sent to arch...@mail-archive.com

Reply via email to