ArrayCollection上的条件表达式区分大小写

问题描述 投票:0回答:1

我有一个来自Hashtag实体的ArrayCollection(数据库/表排序规则都设置为utf8_bin_ci),我想在一个Criteria上进行匹配,但是它是不区分大小写

我已经尝试过'contains','eq','startsWith','endsWith'表达式,但是在匹配时返回null,但是在没有Criteria匹配的情况下,它有很多结果。

如果将strtolower / strtoupper添加到$this->name属性,则它在指定的情况下有效。

如何使标准或此处的匹配不区分大小写?

  public function getHashtags($max = null) {
    $hashtags = $this->hashtags;
    $hashtags->getIterator();
    $crit = Criteria::create()
                    ->where(Criteria::expr()->contains('name', $this->name))
    if (!empty($max)) {
      $crit->setMaxResults($max);
    }

    return $hashtags->matching($crit);
  }
symfony doctrine criteria
1个回答
0
投票

您的代码调用getIterator(),这将防止发生任何数据库魔术,因为它初始化了集合(将加载所有条目),因此您的归类无关紧要。

此外,getIterator()函数使用contains,这显然不区分大小写。

由于您的代码已经提取了所有#标签,因此请对其进行过滤:

contains
© www.soinside.com 2019 - 2024. All rights reserved.