Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd72aa0

Browse files
committed
Merge branch 'backport/DDC288' into 2.5
Backporting: doctrine#6740
2 parents 4bd2f68 + 21f73cf commit fd72aa0

3 files changed

Lines changed: 113 additions & 4 deletions

File tree

lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri
239239
$parameters = $this->expandCriteriaParameters($criteria);
240240

241241
foreach ($parameters as $parameter) {
242-
list($name, $value) = $parameter;
243-
$whereClauses[] = sprintf('te.%s = ?', $name);
244-
$params[] = $value;
242+
list($name, $value, $operator) = $parameter;
243+
244+
$whereClauses[] = sprintf('te.%s %s ?', $name, $operator);
245+
$params[] = $value;
245246
}
246247

247248
$mapping = $collection->getMapping();

lib/Doctrine/ORM/Persisters/SqlValueVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function walkComparison(Comparison $comparison)
6161
}
6262

6363
$this->values[] = $value;
64-
$this->types[] = array($field, $value);
64+
$this->types[] = array($field, $value, $operator);
6565
}
6666

6767
/**
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace Doctrine\Tests\ORM\Functional\Ticket;
4+
5+
use Doctrine\Tests\OrmFunctionalTestCase;
6+
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
7+
use Doctrine\Tests\Models\ECommerce\ECommerceCategory;
8+
use Doctrine\Common\Collections\Criteria;
9+
10+
final class GH6740Test extends OrmFunctionalTestCase
11+
{
12+
/**
13+
* @var int
14+
*/
15+
private $productId;
16+
17+
/**
18+
* @var int
19+
*/
20+
private $firstCategoryId;
21+
22+
/**
23+
* @var int
24+
*/
25+
private $secondCategoryId;
26+
27+
public function setUp()
28+
{
29+
$this->useModelSet('ecommerce');
30+
31+
parent::setUp();
32+
33+
$product = new ECommerceProduct();
34+
$product->setName('First Product');
35+
36+
$firstCategory = new ECommerceCategory();
37+
$secondCategory = new ECommerceCategory();
38+
39+
$firstCategory->setName('Business');
40+
$secondCategory->setName('Home');
41+
42+
$product->addCategory($firstCategory);
43+
$product->addCategory($secondCategory);
44+
45+
$this->_em->persist($product);
46+
$this->_em->flush();
47+
$this->_em->clear();
48+
49+
$this->productId = $product->getId();
50+
$this->firstCategoryId = $firstCategory->getId();
51+
$this->secondCategoryId = $secondCategory->getId();
52+
}
53+
54+
/**
55+
* @group 6740
56+
*/
57+
public function testCollectionFilteringLteOperator()
58+
{
59+
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
60+
$criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategoryId));
61+
62+
self::assertCount(2, $product->getCategories()->matching($criteria));
63+
}
64+
65+
/**
66+
* @group 6740
67+
*/
68+
public function testCollectionFilteringLtOperator()
69+
{
70+
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
71+
$criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategoryId));
72+
73+
self::assertCount(1, $product->getCategories()->matching($criteria));
74+
}
75+
76+
/**
77+
* @group 6740
78+
*/
79+
public function testCollectionFilteringGteOperator()
80+
{
81+
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
82+
$criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategoryId));
83+
84+
self::assertCount(2, $product->getCategories()->matching($criteria));
85+
}
86+
87+
/**
88+
* @group 6740
89+
*/
90+
public function testCollectionFilteringGtOperator()
91+
{
92+
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
93+
$criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategoryId));
94+
95+
self::assertCount(1, $product->getCategories()->matching($criteria));
96+
}
97+
98+
/**
99+
* @group 6740
100+
*/
101+
public function testCollectionFilteringEqualsOperator()
102+
{
103+
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
104+
$criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategoryId));
105+
106+
self::assertCount(1, $product->getCategories()->matching($criteria));
107+
}
108+
}

0 commit comments

Comments
 (0)