How can I specify the columns that are used for the foreign key relation with Class Table Inheritance in Doctrine 2? For example, take the following two classes:
/**
* @Entity
* @InhertanceType("JOINED")
* @DiscriminatorColumn(name="type", type="string")
* @DiscriminatorMap("person" = "Person", "employee" = "Employee")
*/
class Person
{
/** @Id */
public $id;
/** @Column(type="string") */
public $ssn;
}
/** @Entity */
class Employee
{
/** @Column(type="decimal") */
public $salary;
}
With this, Doctrine expects a table structure somewhat along this:
CREATE TABLE `person` (
`id` INT(11) NOT NULL auto_increment,
`ssn` VARCHAR(255) default NULL,
PRIMARY_KEY(`id`)
)
CREATE TABLE `employee` (
`person_id` INT(11) NOT NULL,
`salary` DECIMAL(10,2) default NULL,
PRIMARY_KEY(`person_id`)
)
ALTER TABLE `employee`
ADD CONSTRAINT `person_fk` FOREIGN KEY (`person_id`)
REFERENCES `person` (`id`) ON DELETE CASCADE
There is a foreign key employee.person_id
that points to person.id
. But how can I tell Doctrine which columns to use? I assume that the person.id
reference comes from the @Id
annotation on the Person
class, but what if I want to create the FK to person.ssn
instead (it's conceivable, since SSN are naturally unique).
And what if I have a legacy database where employee.person_id
is called employee.p_id
instead?