mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #8125 from CakeDC/issue/7978
Add support for NOT IN in Model::find() conditions. Refs #7978 fixing regex to take in account IN operator
This commit is contained in:
commit
aa449b194d
2 changed files with 109 additions and 3 deletions
|
@ -2733,7 +2733,7 @@ class DboSource extends DataSource {
|
|||
$keys = array_keys($value);
|
||||
if ($keys === array_values($keys)) {
|
||||
$count = count($value);
|
||||
if ($count === 1 && !preg_match('/\s+(?:NOT|\!=)$/', $key)) {
|
||||
if ($count === 1 && !preg_match('/\s+(?:NOT|IN|\!=)$/', $key)) {
|
||||
$data = $this->_quoteFields($key) . ' = (';
|
||||
if ($quoteValues) {
|
||||
if ($Model !== null) {
|
||||
|
|
|
@ -86,6 +86,112 @@ class ModelReadTest extends BaseModelTest {
|
|||
$this->assertTrue(in_array(false, $doomed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test IN operator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInOperator() {
|
||||
$this->loadFixtures('Product');
|
||||
$Product = new Product();
|
||||
$expected = array(
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 1,
|
||||
'name' => "Park's Great Hits",
|
||||
'type' => 'Music',
|
||||
'price' => 19
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$result = $Product->find('all', array('conditions' => array('Product.id IN' => array(1))));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 2,
|
||||
'name' => "Silly Puddy",
|
||||
'type' => 'Toy',
|
||||
'price' => 3
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 3,
|
||||
'name' => "Playstation",
|
||||
'type' => 'Toy',
|
||||
'price' => 89
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 4,
|
||||
'name' => "Men's T-Shirt",
|
||||
'type' => 'Clothing',
|
||||
'price' => 32
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 5,
|
||||
'name' => "Blouse",
|
||||
'type' => 'Clothing',
|
||||
'price' => 34
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 6,
|
||||
'name' => "Electronica 2002",
|
||||
'type' => 'Music',
|
||||
'price' => 4
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 7,
|
||||
'name' => "Country Tunes",
|
||||
'type' => 'Music',
|
||||
'price' => 21
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 8,
|
||||
'name' => "Watermelon",
|
||||
'type' => 'Food',
|
||||
'price' => 9
|
||||
)
|
||||
)
|
||||
);
|
||||
$result = $Product->find('all', array('conditions' => array('Product.id NOT IN' => array(1))));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 1,
|
||||
'name' => "Park's Great Hits",
|
||||
'type' => 'Music',
|
||||
'price' => 19
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Product' => array(
|
||||
'id' => 2,
|
||||
'name' => "Silly Puddy",
|
||||
'type' => 'Toy',
|
||||
'price' => 3
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$result = $Product->find('all', array('conditions' => array('Product.id IN' => array(1, 2))));
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testGroupBy method
|
||||
*
|
||||
|
@ -8079,8 +8185,8 @@ class ModelReadTest extends BaseModelTest {
|
|||
|
||||
/**
|
||||
* test after find callback on related model
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRelatedAfterFindCallback() {
|
||||
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
|
||||
|
|
Loading…
Reference in a new issue