Skip to content

Instantly share code, notes, and snippets.

@abeger
Created April 25, 2012 03:22
Show Gist options
  • Save abeger/2485973 to your computer and use it in GitHub Desktop.
Save abeger/2485973 to your computer and use it in GitHub Desktop.
Handle a table with two foreign keys to another table with Doctrine
//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'));
//...
}
}
$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