使用 Zend_Db_table 连接时出现重复的列名
我有两张桌子。它们都有一个名为“标题”的列。当我使用以下代码片段连接两个表时,我无法访问标题列之一。
$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false);
$select->join("service","service.id = lecture.service_id");
return $select;
有没有办法访问这两列?
I have two tables. Both of them have a column named 'title'. When I use the following code snippet to join two tables, I can't access one of the title column.
$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false);
$select->join("service","service.id = lecture.service_id");
return $select;
is there a way to access both columns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要重命名其中一列,以免与另一列冲突。如果将数组作为可选的第三个参数传递给 join(),则可以指定要从连接表中检索哪些列。如果数组中的一个或多个条目经过哈希处理,则哈希键将用作属性名称。使用下面的代码,您可以在查询结果中将服务表的标题列引用为“service_title”。如果您需要服务表中的其他列,请将它们添加到数组中,根据需要使用或不使用哈希。
You need to rename one of the columns so it doesn't conflict with the other. If you pass an array as the optional 3rd argument to join(), you can specify which columns to retrieve from the joined table. If one or more of the entries in the array is hashed, then the hash key will be used as the property name. With the code below, you can refer to the title column of the service table as "service_title" in your query results. If you want other columns from the service table, add them to the array, with or without hashes as desired.
也许它可以完成这项工作。
问候。
Maybe It can do the job.
Regard´s.