doctrine orx

Solutions on MaxInterview for doctrine orx by the best coders in the world

showing results for - "doctrine orx"
Leni
21 Feb 2018
1/**
2 * orX stands for OR Expressions. They may contain multiple standard expressions
3 * such as eq, neq, instanceof, etc. OrX can be used in two ways:
4 * 1. Via Doctrine's Criteria library inside of an entity/class
5 * 2. Via the QueryBuilder library inside of a query
6 */
7
8// Inside of a class
9use Doctrine\Common\Collections\Criteria;
10class Company
11{
12  /**
13   * @ORM\OneToMany(targetEntity="Employee", mappedBy="company")
14   */
15  protected employees;
16
17  function findDevelopers(): Collection
18  {
19	$expr     = Criteria::expr();
20	$criteria = Criteria::create();
21
22    $criteria->where($expr->eq('position', 'developer'));
23
24    return $this->employees->matching($criteria);
25  }
26}
27                        
28// Inside of a query via querybuilder
29function getStuff(): Array
30{
31  $qb = $entityManager->createQueryBuilder();
32  
33  $qb->select('assoc1.thing as thing1, assoc2.thing as thing2')
34      ->from(assoc1::class, 'assoc1')
35      ->innerJoin(assoc2::class, 'assoc2', 'with', 'assoc1.someId = assoc2.someId')
36      ->where(
37        $qb->expr()->orX(
38          $qb->expr()->eq('assoc1.thing', 'foo'),
39          $qb->expr()->neq('assoc2.thing', 'bar')
40        )
41      )
42      ->getQuery()
43      ->getResult();
44}
queries leading to this page
doctrine orxandx doctrinedoctrine orx