0
技術擴展擴展模型:ORM,學說1.1.6,KohanaPHP主義用柱聚集
教義1.1.6。我如何在不同的表格上傳播模型?
詳細情況:
我有實體類包含一個ID,登錄名和密碼,並有一個EMAILADDRESS,許多地址和其他一些關係。我有兩個其他類,公司和個人,擴展實體。我想用Column aggregation來擴展它們,所以所有的登錄和密碼信息都保存在一個地方。現在我想添加特定的列到我的Person類(名字,姓氏等),但我找不到如何做到這一點。文檔給出的唯一例子是沒有額外列的例子。
當前類
實體類:
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 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生成:
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
燦有人告訴我如何做到這一點?
@Larry_Croft:所以基本上我想要的是不可能的?我必須將我的人員和公司信息放在一張表中? – 2010-02-25 07:27:59
是的,至少有列聚合。我會爲我的答案添加一個替代解決方案。 – 2010-02-25 09:45:33
謝謝。你建議我的舊情況(沒有冒犯,你不知道)。我想我會試着延長你的/我的/我們的想法。再次感謝你的幫助! – 2010-02-25 10:21:57