Re: Many-to-many question ...
Re: Many-to-many question ...
- Subject: Re: Many-to-many question ...
- From: Owen McKerrow <email@hidden>
- Date: Thu, 25 Oct 2007 17:02:20 +1000
We use approach 2, works fine for us. Others may have other ideas.
Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
"I like the way this project has somehow, against all common sense,
got itself made."
- Peter Jackson, "The Lord of The Rings"
On 25/10/2007, at 4:58 PM, Johann Werner wrote:
Related to join tables containing additional attributes:
In a relation A<-->>AB<<-->B with a specific A1 that can have more
than one relation to a specific B1 (thus only differing in the
additional attributes) the standard primary key as a compound of
the primary keys of A1 and B1 would not be unique any more.
What is the best practice in this case:
1) adding a third id field to AB and add it to the compound key
using the option "use as primary key"
or
2) adding an additional id field that is solely used as primary key
and using the former compound key only as foreign key for the
relationships (in that case the table would be more like a "normal"
table than a many-2-many table)
or
3) leaving the AB table as it is and praying that no user will ever
want several A1<->B1 relations ;-)
jw
Am 25.10.2007 um 04:07 schrieb Lachlan Deck:
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");
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:
40isd.uni-stuttgart.de
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:
40uow.edu.au
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