使用Zend_Db_table连接时重复的列名称

时间:2009-12-04 21:22:39

标签: zend-db-table

我有两张桌子。它们都有一个名为'title'的列。当我使用以下代码片段连接两个表时,我无法访问其中一个标题列。

    $select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
    $select->setIntegrityCheck(false);
    $select->join("service","service.id = lecture.service_id");
    return $select;

有没有办法访问这两列?

2 个答案:

答案 0 :(得分:9)

您需要重命名其中一列,以免与另一列发生冲突。如果将数组作为join()的可选第3个参数传递,则可以指定要从连接表中检索的列。如果对数组中的一个或多个条目进行哈希处理,则哈希键将用作属性名称。使用下面的代码,您可以在查询结果中将服务表的标题列称为“service_title”。如果您需要服务表中的其他列,请将它们添加到数组中,根据需要添加或不使用哈希值。

$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false);
$select->join("service", "service.id = lecture.service_id",
              array("service_title" => "service.title");
return $select;

答案 1 :(得分:1)

$select = $this->select();
$select->from(array('t'=>'table1'), array('table_title AS title_first','table_sendo_colun','table_third_colun'));
$select->setIntegrityCheck(false);
$select->join("service","service.id = t.service_id");
return $select;

也许它可以完成这项工作。

Regard's。