技术:ORM,条令1.1.6,KohanaPHP
第1.1.6条。如何在不同的桌子上分布模型?
具体情况:
我有一个包含ID、登录名和密码的类实体,它有一个emailaddress、多个地址和一些其他关系。我还有另外两个类,Company和Person,它们扩展了实体。我想用
Column aggregation
所以所有的登录和密码信息都保存在一个地方。现在我想给我的Person类添加特定的列(firstname、lastname等),但是我找不到如何做到这一点。文档给出的唯一示例是没有额外列的示例。
当前类别
实体类:
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)
));
}
}
人员类别:
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,
));
}
}
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
有人能告诉我怎么做吗?