• 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: Wolfram Stebel <email@hidden>
  • Date: Tue, 26 Jul 2005 22:56:00 +0200

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

  • Follow-Ups:
    • Re: many-to-many with attributes?
      • From: Arturo Perez <email@hidden>
References: 
 >many-to-many with attributes? (From: Jim Zajkowski <email@hidden>)

  • Prev by Date: AW: Dynamic Image resizing for thumbnail view with correct Aspect...
  • Next by Date: Re: AW: EOModeler Question
  • Previous by thread: Re: many-to-many with attributes?
  • Next by thread: Re: many-to-many with attributes?
  • Index(es):
    • Date
    • Thread