2013-03-12 74 views
3

怎麼辦查詢:加入Zend框架中使用別名

$name = $this->_dbTable->info('name'); 
$result = $this->_dbTable->select()->from($name)->setIntegrityCheck(false); 
$result->join(array('t' => "$name.tipo")), "t.id = $name.id"); 

其中「$ name.tipo」是連接表的名稱。

回答

2

根據tipo的值,您無法按每行加入不同的表。 SQL要求在準備查詢時修復這些表,因爲發現了從給定列中獲取的數據值,所以該表不能更改。

您的設計被稱爲Polymorphic Associations,它是非關係設計。在SQL中執行此操作非常尷尬。

查看我的介紹Practical Object Oriented Models In SQL的一些替代品。