• 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: many-to-many with attributes?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: many-to-many with attributes?


  • Subject: Re: many-to-many with attributes?
  • From: Arturo Perez <email@hidden>
  • Date: Tue, 26 Jul 2005 17:21:43 -0400

Hi Jim,

I don't understand what the below from Wolfram is all about. I've never had to do that and I have 5-way join tables with attributes. Assuming that your model is up to snuff...

Here's what I do:

User u = (User)...objectMatchingKeyAndValue(...);
/** @TypeInfo UserGroup */
NSArray ugArray = (NSArray)u.valueForKey("groups");
<> accesslevel= (<>)((NSKeyValueCoding)ug.lastObject()).valueForKey("accessLevel");


One could shortcut the above
User u = (User)...objectMatchingKeyAndValue(...);
/** @TypeInfo <> */
NSArray accessLevels = (NSArray)u.valueForKey("groups.accessLevel");

Some notes on the above. The <> denotes the unspecified class of your access level thing (that is, _I_ don't know what the class is).
The TypeInfo thing lets WOBuilder know what the types of the objects contained in the NSArray are so it can should you binding keys properly.


As long as you unflatten the relationships so that you can get at the intermediate join table object you should be fine.

Wolfram Stebel wrote:
Am 26.07.2005 19:34 Uhr schrieb "Jim Zajkowski" unter
<email@hidden>:


Hi there,

What's the best way to handle a many-to-many relationship that has an
attribute on the relation?

That is, let's say I have a table of users, and a table of groups.  I
want a m-to-m relation between them, since clearly more than one user
can belong to a group, and I'd like to see what users are in a group.

But I also want to include some form of "access level" (e.g.,
moderator, administrator, regular user).

In DB land I'd model this by having an additional attribute on the
users-groups table.  But when I've done that in EOModeler, it creates
a flattened relation, and so there isn't a way to see that attribute.

So, what's the best way to do it?  Not flatten the relation and walk
the m-to-m by hand?

The answers you received up to now are not solving your problem. I also missed a way to add an attribute to an relation and the possibility to access and edit it. I fetch it myself as can be seen below, so you need to know the primary keys of the related objects, and you have a "cheep" fetch on one row, which you Dipl. Inform. Wolfram Stebel, bugs&errors Flutgrabenstr. 19, 35576 Wetzlar Tel. 06441/47633 Mailto:email@hidden Web: www.bugs-and-errors.de can modify and save again.

If anybody knows better, let me know!

Wolfram

Sample:
Person<--->>group_person<<--->group
                ^
                ^
                |
                |
                |
                v
            Function_Key

Setting and getting Function_Key from Group is as follows:


public EOGenericRecord getFunktionKey ( EOEditingContext ec, CPerson aPerson ) { if ( NSLog.debugLoggingAllowedForLevel ( NSLog.DebugLevelDetailed ) ) { NSLog.out.appendln ( EOUtilities.primaryKeyForObject ( ec, aPerson ) ); NSLog.out.appendln ( EOUtilities.primaryKeyForObject ( ec, this ) ); } NSMutableDictionary aDict = new NSMutableDictionary (); aDict.takeValueForKey ( aPerson, "person" ); aDict.takeValueForKey ( this, "groups" ); NSArray result = EOUtilities.objectsWithFetchSpecificationAndBindings ( ec, "Group_Person", "onePersonForGroup", aDict ); if ( ( result == null ) || ( result.count () != 1 ) ) { // should not happen if ( NSLog.debugLoggingAllowedForLevel ( NSLog.DebugLevelDetailed ) ) { NSLog.out.appendln ( "missing relation for : " + aPerson.name () ); } return null; } else { EOGenericRecord eo = ( EOGenericRecord ) result.objectAtIndex ( 0 ); return ( ( EOGenericRecord ) eo.valueForKey ( "function_key" ) ); } }

public void setFunctionKey ( EOEditingContext ec, CPerson aPerson,
EOGenericRecord functionKey )
{
if ( NSLog.debugLoggingAllowedForLevel ( NSLog.DebugLevelDetailed )
)
{
NSLog.out.appendln ( EOUtilities.primaryKeyForObject ( ec,
aPerson ) );
NSLog.out.appendln ( EOUtilities.primaryKeyForObject ( ec, this
) );
}
NSMutableDictionary aDict = new NSMutableDictionary ();
aDict.takeValueForKey ( aPerson, "person" );
aDict.takeValueForKey ( this, "groups" );
NSArray result =
EOUtilities.objectsWithFetchSpecificationAndBindings ( ec, "Group_Person",
"onePersonForGroup", aDict );
if ( ( result == null ) || ( result.count () != 1 ) )
{
// should not happen
if ( NSLog.debugLoggingAllowedForLevel (
NSLog.DebugLevelDetailed ) )
{
NSLog.out.appendln ( "missing relation for : " +
aPerson.name () );
}
}
else
{
EOGenericRecord eo = ( EOGenericRecord ) result.objectAtIndex (
0 );
eo.takeValueForKey ( functionKey, "function_key" );
}
}



_______________________________________________ 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


_______________________________________________ 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
References: 
 >Re: many-to-many with attributes? (From: Wolfram Stebel <email@hidden>)

  • Prev by Date: Re: AW: EOModeler Question
  • Next by Date: Re: many-to-many with attributes?
  • Previous by thread: Re: many-to-many with attributes?
  • Next by thread: Re: many-to-many with attributes?
  • Index(es):
    • Date
    • Thread