[DataObjects] many-to-many relationship?
| From: | Ryan King | Date: | Wed, 14 Jan 2004 15:00:44 +0000 |
| Subject: | [DataObjects] many-to-many relationship? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-10157@lists.php.net to get a copy of this message | ||
I have a question regarding DataObjects. I have a situation where I need to join a many-to-many
relationship. I'm doing this with an extra table in the middle. Here's the general idea:
table1 join_table table2
id<----------------------------table1_id .
. table2_id--------------------------->id
. .
. .
I would like to be able to load all of table2's related data into the table1 dataobject. I can
do this manually by looping through the links like this:
$link = $this->getLink('id', 'join_table', 'table1_id');
do {
$table2Obj = $link->getLink('table2_id','table2','id');
$this->myVar[] = $table2Obj->getStuff();
} while($link->fetch());
Is there a cleaner way to do this? Is there a way that I can establish a relationship like this in
my .ini file? I would like to be able to do getLinks() and have all this data loaded in.
Thanks,
Ryan
---------
http://homepage.mac.com/ryansking/