首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有多个FROM表的TableGateway

具有多个FROM表的TableGateway
EN

Stack Overflow用户
提问于 2013-01-16 09:16:26
回答 1查看 8.5K关注 0票数 5

我想在INNER JOIN中的两个表之间做一个简单的Zend2。

具体来说,我想在Zend2中这样做:

SELECT * FROM foo, bar WHERE foo.foreign_id = bar.id;

我有一个FooTable

代码语言:javascript
复制
class FooTable
{
  protected $tableGateway;

  public function __construct(TableGateway $tableGateway)
  {
    $this->tableGateway = $tableGateway;
  }

  public function get($id)
  {
    $rowset = $this->tableGateway->select(function (Select $select) {
      $select->from('foo');
    });
  }
}

$select->from('foo');返回一个错误:

==> ,因为这个对象是在构造函数中用表和/或模式创建的,所以它是只读的.

因此,我不能调整FROM语句来匹配FooTableBarTable之间的简单内部连接。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-17 01:56:53

我希望这将有助于您的旅程,因为这是一个工作的例子,我有:

代码语言:javascript
复制
namespace Pool\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;

class IpaddressPool extends AbstractTableGateway
{
    public function __construct($adapter)
    {
        $this->table = 'ipaddress_pool';

        $this->adapter = $adapter;

        $this->initialize();
    }

    public function Leases($poolid)
    {
        $result = $this->select(function (Select $select) use ($poolid) {
            $select
                ->columns(array(
                    'ipaddress',
                    'accountid',
                    'productid',
                    'webaccountid'
                ))
                ->join('account', 'account.accountid = ipaddress_pool.accountid', array(
                    'firstname',
                    'lastname'
                ))
                ->join('product_hosting', 'product_hosting.hostingid = ipaddress_pool.hostingid', array(
                    'name'
                ))
                ->join('webaccount', 'webaccount.webaccountid = ipaddress_pool.webaccountid', array(
                    'domain'
                ))->where->equalTo('ipaddress_pool.poolid', $poolid);
        });

        return $result->toArray();
    }
}
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14354802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档