Created
April 25, 2012 03:22
-
-
Save abeger/2485973 to your computer and use it in GitHub Desktop.
Handle a table with two foreign keys to another table with Doctrine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Table1 has two foreign keys to Table2 | |
abstract class Table1 extends Doctrine_Record { | |
public function setUp() { | |
//... | |
$this->hasOne('Table2 as FirstAlias', array( | |
'local' => 'table2_id_first', | |
'foreign' => 'id')); | |
$this->hasOne('Table2 as SecondAlias', array( | |
'local' => 'table2_id_second', | |
'foreign' => 'id')); | |
//... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$table1_instance = //load your object | |
//reference object pointed at by first foreign key | |
$table1_instance['FirstAlias']; | |
//reference object pointed at by second foreign key | |
$table1_instance['SecondAlias']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment