Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Many-to-many question ...





2007/10/25, Lachlan Deck <email@hidden>:
On 25/10/2007, at 11:17 AM, Shagor Ghani wrote:

> Have a quick question around join tables storing M2M
> relationships.  I need
> to store a M2M relationship and created a table for it using
> Property>Join
> in Many-to-Many option from within EOModeler itself.  This table
> has two
> columns, id1 and id2, both of which are primary and which together
> produce a
> unique record.  In my code, I've been doing creating new rows into
> this
> table using the standard
> object.addObjectToBothSidesOfRelationshipWithKey(
> object, key ) call.  Now, though, I also need to store additional
> values
> within this record, for example a boolean bit indicating whether
> the record
> is active or not.  How is this done?  If I manually add a 3rd
> attribute
> column, what call is then used to update/create new  record(s)?

You have two choices with M2M Join tables.
A<-->>AB<<-->B

1) flatten the relationships... so that you're adding to both sides
of relationship two records on either side of the join. Join records
using EOGenericRecord and don't have any logic in them.

A myA = (A)EOUtilties.createAndInsertInstance(ec, "A");
B myB = (B)EOUtilties.createAndInsertInstance(ec, "B");
myA.addObjectToBothSidesOfRelationshipWithKey(myB, "bs");

How this work? Do you need to set the EOmodel in some way?

2) don't flatten the relationships
A myA = (A)EOUtilties.createAndInsertInstance(ec, "A");
AB myAB = (AB)EOUtilties.createAndInsertInstance(ec, "AB");
B myB = (B)EOUtilties.createAndInsertInstance(ec, "B");

myAB.setSomeOtherKey (...);
myA.addObjectToBothSidesOfRelationshipWithKey(myAB, "abs");
myAB.addObjectToBothSidesOfRelationshipWithKey(myB, "abs");

with regards,
--

Lachlan Deck

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

This email sent to email@hidden



--
Daniele Corti
AIM: S0CR4TE5
Messenger: email@hidden

--
Computers are like air conditioners -- they stop working properly if you open
WINDOWS

--
What about the four lusers of the apocalypse? I nominate:
"advertising", "can't log in", "power switch" and "what backup?"
--Alistair Young
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/email@hidden

This email sent to email@hidden

References: 
 >Many-to-many question ... (From: "Shagor Ghani" <email@hidden>)
 >Re: Many-to-many question ... (From: Lachlan Deck <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.