Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带数组的where子句_Php_Sql_Symfony_Doctrine Orm_Arraycollection - Fatal编程技术网

Php 带数组的where子句

Php 带数组的where子句,php,sql,symfony,doctrine-orm,arraycollection,Php,Sql,Symfony,Doctrine Orm,Arraycollection,我有一个名为“发票”的实体,其中有许多“订阅”,因此“发票”和“订阅”处于多对多关系中 class Invoice { /** * @ORM\Column(type="integer") */ protected $a; /** * @ORM\Column(type="integer") */ protected $b; /** * @ORM\ManyToMany(targetEntity="Subscription", inversedBy="invoices") */ pro

我有一个名为“发票”的实体,其中有许多“订阅”,因此“发票”和“订阅”处于多对多关系中

class Invoice
{
/**
 * @ORM\Column(type="integer")
 */
protected $a;

/**
 * @ORM\Column(type="integer")
 */
protected $b;

/**
 * @ORM\ManyToMany(targetEntity="Subscription", inversedBy="invoices")
 */
protected $subscriptions;

public function __construct()
{
    $this->subscriptions = new ArrayCollection();
}

//typical setters and getters
}
使用querybuilder,如何使用子描述上的where子句获得一组匹配的实体

$subscription = ;//something pulled from the db and is a "subscription" object
$em->createQueryBuilder()
            ->select('p')
            ->from('Invoice', 'p')
            ->where('p.a = :a')
            ->andWhere('p.b = :b')
            ->andWhere('p.subscriptions has :subscription')   //this line here I need help
            ->setParameter('a', 1)
            ->setParameter('b', 2)
            ->setParameter('subscription', $subscription)
            ->getQuery()
            ->getResult();

该原则为此目的有特别声明
成员。另一个解决方案是进行子查询

->andWhere(':subscription MEMBER OF p.subscriptions') 

您可以在。

条令中找到关于这一目标的特别声明
成员。另一个解决方案是进行子查询

->andWhere(':subscription MEMBER OF p.subscriptions') 

您可以在中找到示例。

我不完全确定,但也许您应该加入订阅

$subscription = ;//something pulled from the db and is a "subscription" object
$em->createQueryBuilder()
        ->select('p')
        ->from('Invoice', 'p')
        ->join('p.subscriptions', 'subscription');
        ->where('p.a = :a')
        ->andWhere('p.b = :b')
        ->andWhere('subscription = :subscription')   //this line here I need help
        ->setParameter('a', 1)
        ->setParameter('b', 2)
        ->setParameter('subscription', $subscription)
        ->getQuery()
        ->getResult();

或者,如果订阅具有id,则可以使用该id而不是对象。

我不完全确定,但也许您应该加入订阅

$subscription = ;//something pulled from the db and is a "subscription" object
$em->createQueryBuilder()
        ->select('p')
        ->from('Invoice', 'p')
        ->join('p.subscriptions', 'subscription');
        ->where('p.a = :a')
        ->andWhere('p.b = :b')
        ->andWhere('subscription = :subscription')   //this line here I need help
        ->setParameter('a', 1)
        ->setParameter('b', 2)
        ->setParameter('subscription', $subscription)
        ->getQuery()
        ->getResult();
或者,如果订阅具有id,则可以使用该id而不是对象