Skip to content

ContainedBy Query #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Parse/ParseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public function endsWith($key, $value)
return $this;
}

/**
/**
* Adds a constraint for finding string values that contain a provided
* string. This may be slow for large datasets.
*
Expand All @@ -404,6 +404,22 @@ public function contains($key, $value)
return $this;
}

/**
* Adds a constraint to the query that requires a particular key's value to
* be contained by the provided list of values. Get objects where all array elements match.
*
* @param string $key The key to check.
* @param mixed $value The values that will match.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function containedBy($key, $value)
{
$this->addCondition($key, '$containedBy', $value);

return $this;
}

/**
* Adds a constraint for finding string values that contain a provided
* string using Full Text Search
Expand Down
25 changes: 24 additions & 1 deletion tests/Parse/ParseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,29 @@ public function testContainsAllDateArrayQueries()
);
}

public function testContainedByQuery()
{
Helper::clearClass('NumberSet');
$obj1 = ParseObject::create('TestObject');
$obj2 = ParseObject::create('TestObject');
$obj3 = ParseObject::create('TestObject');
$obj1->setArray('numbers', [0, 1, 2]);
$obj2->setArray('numbers', [2, 0]);
$obj3->setArray('numbers', [1, 2, 3, 4]);
$numberSet = [$obj1, $obj2, $obj3];

ParseObject::saveAll($numberSet);

$query = new ParseQuery('TestObject');
$query->containedBy('numbers', [1, 2, 3, 4, 5]);
$results = $query->find();
$this->assertEquals(
1,
count($results),
'Did not return correct number of objects.'
);
}

public function testContainsAllObjectArrayQueries()
{
Helper::clearClass('MessageSet');
Expand Down Expand Up @@ -2338,7 +2361,7 @@ public function testUnknownCondition()
'\Parse\ParseException',
'Unknown condition to set'
);

$query = new ParseQuery('TestObject');
$query->_setConditions([
'unrecognized' => 1
Expand Down