【问题标题】:Doctrine orderBy with PostgreSQL json column (could not identify an equality operator for type json)带有 PostgreSQL json 列的 Doctrine orderBy(无法识别 json 类型的相等运算符)
【发布时间】:2017-10-27 19:11:42
【问题描述】:

我有两个实体 Export 和 ExportItem。导出实体中的一列是config json 类型(这是我数据库中唯一具有 json 类型的列)。

部分出口实体:

/**
 * @ORM\Column(type="json", nullable=true)
 */
protected $config;

/**
 * @var ArrayCollection|ExportItem[]
 * @ORM\OneToMany(targetEntity="Entity\ExportItem", mappedBy="export", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
 */
protected $items;

ExportItem 实体的一部分:

/**
 * @var Export
 * @ORM\ManyToOne(targetEntity="Entity\Export", inversedBy="items")
 */
protected $export;

我想按附加的 ExportItems 数量订购 Exports,但下一个查询抛出错误“无法识别 json 类型的相等运算符

$this->createQueryBuilder('o')
     ->join('o.suit', 's')
     ->where('s.id = :suitId')
     ->setParameter('suitId', $suit->getId())         
     ->select('COUNT(i) AS HIDDEN nbrItems', 'o.id')
     ->leftJoin('o.items', 'i')
     ->orderBy('nbrItems', $orderDir)
     ->groupBy('o');

【问题讨论】:

    标签: postgresql doctrine-orm


    【解决方案1】:

    我找到了解决方案。只需要添加

    ->groupBy('o.id');
    

    在查询中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-30
      • 2017-09-28
      • 1970-01-01
      • 2013-10-07
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多