Re: SOLVED Question for the Java Gurus
Re: SOLVED Question for the Java Gurus
- Subject: Re: SOLVED Question for the Java Gurus
- From: Owen McKerrow <email@hidden>
- Date: Fri, 23 Apr 2004 10:40:45 +1000
On 23/04/2004, at 12:01 AM, Sam Barnum wrote:
Or, just use NSArray's valueForKey() method, which calls valueForKey()
for each item in an array
NSArray arrayOfEats; // assume this exists
NSArray arrayOfFrogs = (NSArray)arrayOfEats.valueForKey("frog");
NSArray arrayOfFoods = (NSArray)arrayOfEats.valueForKey("food");
So does it work back the other way as well ?
As in setValueForKey ?
The senario :
As an example, I have a Frequency table and a Frequency Category table,
joined together by a many-to-many through a join table, jCatFreq.
Now I can't flatten the relationship as I store an order attribute in
it, so that Frequencies of a particular Category are displayed
correctly on the screen.
Now there could possible be lots of Frequencies to choose from so I
want to display them as check box's in a WOTable.
So my understanding is that I need to rip the Frequencies the category
currently owns from the join table objects ( i.e. the code that Ive
been talking about in the last couple of emails ) and then compare this
list with the list of all Frequencies and tick the ones that they have
already selected. However then I need to be able to take back the list
after it has been edited ( more objects ticked, some un-ticked etc )
and update the Categories jFeqCat array with current list of
relationships it would have.
So would setValueForKey() on the array do that for me ? Will it get rid
of the no longer needed items and add the new ones ?
Thanks Again
Owen
On Apr 21, 2004, at 10:06 PM, Owen McKerrow wrote:
Yeah sorry, re-read the email and yes I didn't explain myself very
well. The function was just an example really, just to put the
Object tempOb = (entity)array.objectAtIndex(0); line in some form of
context.
The question was basically, given the name of a class as a string, is
there anyway to use that String for casting an object to the class
type of class who's name is the contents of the string.
In the end I did it another way :
/**This class is deisgned to take a NSArray of objects from a join
table between two entities and return a NSArray of the objects from
one of the entities.
That is if you have 2 tables 'Frog' and 'Food" with the join table
'Eats' between them, you can pass this class the Frogs NSArray of
Eats objects and ask for an NSArray of Food items that match the
given relationship.
It only every really needs to be used when there is something in the
join table that doesn't allow it to be flattened.*/
/**
Given an Array of join table objects and a relationship name, it
will seek to return an array of objects from the other side of that
relationship
@param objects The array of objects you wish to strip
@param relationship The relationship that you wish to get an array
of objects from
*/
public static NSMutableArray stripJoin(NSArray objects, String
relationship) throws Exception
{
int i;
NSMutableArray wantedObjects = new NSMutableArray();
for (i=0;i < objects.count();i++) {
Object temp = objects.objectAtIndex(i);
Method tempMethod = temp.getClass().getMethod(relationship,null);
wantedObjects.addObject(tempMethod.invoke(temp,null));
}
return wantedObjects;
}
Owen
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -
People who prefer typing to pointing then seem to prefer acronyms to
save typing :-)
-Denis Stanton, On people using Command Line Interfaces
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.