小编mik*_*uby的帖子

Doctrine 相同的查询,getResult 与 getArrayResult 返回不同的结果

构建以下查询:

$q = $this
    ->createQueryBuilder('a')
    ->select('a')
    ->where('a.account = :accountId')
    ->andWhere('a.organization = :organization_id')
    ->setParameters(
        array(
            'accountId' => $account_id,
            'organization_id' => $organization_id,
        )
    )
    ->getQuery();
Run Code Online (Sandbox Code Playgroud)

调用 getResult() 时(并计算结果集): $attributes = count($q->getResult());结果返回 1 行(这是不正确的)。

但是,当调用 getResultArray$attributes = count($q->getArrayResult());结果是 2(这是正确的)

表架构:

CREATE TABLE 'accountattribute' (
  'account_id' int(11) NOT NULL,
  'organization_id' int(11) NOT NULL,
  'dataKey' varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  'dataValue' text COLLATE utf8_unicode_ci NOT NULL,
  'updated' datetime NOT NULL,
  'created' datetime NOT NULL,
  PRIMARY KEY ('account_id','organization_id','dataKey'),
  KEY 'organization_id' ('organization_id'), …
Run Code Online (Sandbox Code Playgroud)

mysql symfony doctrine-orm

2
推荐指数
1
解决办法
9538
查看次数

标签 统计

doctrine-orm ×1

mysql ×1

symfony ×1