Techniques: ORM, Doctrine 1.1.6, KohanaPHP
With Doctrine 1.1.6. How do I spread a model over different tables?
Detailed situation:
I have the class Entity which contains an ID, login and password and has one emailaddress, many addresses and some other relations. I have two other classes, Company and Person, which extend Entity. I want to extend them using Column aggregation so all login and password information is saved in one place. Now I want to add specific columns to my Person class (firstname, lastname, etc), but I can't find how to do this. The only example the documentation gives is one without extra columns.
Current classes
Entity class:
class Entity extends Doctrine_Record
{
public function setTableDefinition() {
$this->setTableName('entity');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'unsigned' => 0,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('login', 'string', 64, array(
'type' => 'string',
'length' => 64,
'fixed' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('password', 'string', 64, array(
'type' => 'string',
'length' => 64,
'fixed' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('created', 'date', null, array(
'type' => 'date',
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('modified', 'date', null, array(
'type' => 'date',
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->setSubclasses(array(
'Person' => array("type" => 1)
));
}
}
Person Class:
class Person extends Entity
{
public function setTableDefinition() {
$this->setTableName('person');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'unsigned' => 0,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('firstname', 'string', 255, array(
'type' => 'string',
'length' => 255,
'fixed' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('insertion', 'string', 64, array(
'type' => 'string',
'length' => 64,
'fixed' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('lastname', 'string', 255, array(
'type' => 'string',
'length' => 255,
'fixed' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
}
}
SQL generated:
CREATE TABLE `person` (
`id` INT AUTO_INCREMENT,
`firstname` VARCHAR(255) NOT NULL,
`insertion` VARCHAR(64),
`lastname` VARCHAR(255) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = INNODB
CREATE TABLE `entity` (`
id` INT AUTO_INCREMENT,
`login` VARCHAR(64) NOT NULL,
`password` VARCHAR(64) NOT NULL,
`created` DATE,
`modified` DATE,
PRIMARY KEY(`id`)
) ENGINE = INNODB
Can somebody tell me how to accomplish this?