Skip to content

Commit e98ebc4

Browse files
committed
Add encode option to ParseQuery:find
the ability to get the result from a ParseQuery->find() without the results being decoded into ParseObject instances. Similar to parse-community#26
1 parent 9fb3ce5 commit e98ebc4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Parse/ParseQuery.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,11 @@ public function aggregate($pipeline)
610610
* Execute a find query and return the results.
611611
*
612612
* @param bool $useMasterKey
613+
* @param bool $decodeObjects If set to false, will not return raw data instead of ParseObject instances
613614
*
614615
* @return ParseObject[]
615616
*/
616-
public function find($useMasterKey = false)
617+
public function find($useMasterKey = false, $decodeObjects = true)
617618
{
618619
$sessionToken = null;
619620
if (ParseUser::getCurrentUser()) {
@@ -627,6 +628,13 @@ public function find($useMasterKey = false)
627628
null,
628629
$useMasterKey
629630
);
631+
if (!$decodeObjects) {
632+
if (array_key_exists('results', $result)) {
633+
return $result['results'];
634+
} else {
635+
return [];
636+
}
637+
}
630638
$output = [];
631639
foreach ($result['results'] as $row) {
632640
$obj = ParseObject::create($this->className, $row['objectId']);

tests/Parse/ParseQueryTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,6 +2365,34 @@ public function testAndQueriesVaryingClasses()
23652365
]);
23662366
}
23672367

2368+
public function testQueryFindEncoded()
2369+
{
2370+
$obj = new ParseObject('TestObject');
2371+
$obj->set('name', 'John');
2372+
$obj->set('country', 'US');
2373+
$obj->save();
2374+
2375+
$obj = new ParseObject('TestObject');
2376+
$obj->set('name', 'Bob');
2377+
$obj->set('country', 'US');
2378+
$obj->save();
2379+
2380+
$obj = new ParseObject('TestObject');
2381+
$obj->set('name', 'Joel');
2382+
$obj->set('country', 'CA');
2383+
$obj->save();
2384+
2385+
$query = new ParseQuery('TestObject');
2386+
$query->ascending(['country','name']);
2387+
$results = $query->find(false, false);
2388+
2389+
$this->assertEquals(3, count($results));
2390+
2391+
$this->assertEquals('Joel', $results[0]['name']);
2392+
$this->assertEquals('Bob', $results[1]['name']);
2393+
$this->assertEquals('John', $results[2]['name']);
2394+
}
2395+
23682396
/**
23692397
* @group query-set-conditions
23702398
*/

0 commit comments

Comments
 (0)