教义findBy'不等于' [英] Doctrine findBy 'does not equal'

查看:250
本文介绍了教义findBy'不等于'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何执行

WHERE id != 1

在Doctrine?

我有这么远

$this->getDoctrine()->getRepository('MyBundle:Image')->findById(1);

但是我该怎么做不等于?

But how do I do a "do not equals"?

这可能是愚蠢的,但是我找不到任何这个引用?

This maybe daft, but I cannot find any reference to this?

谢谢

推荐答案

没有内置的方法允许您打算做什么。

There is no built-in method that allows what you intend to do.

您必须向存储库添加一个方法,像这样:

You have to add a method to your repository, like this:

public function getWhatYouWant()
{
    $qb = $this->createQueryBuilder('u');
    $qb->where('u.id != :identifier')
       ->setParameter('identifier', 1);

    return $qb->getQuery()
          ->getResult();
}

希望这有帮助。

这篇关于教义findBy'不等于'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆