Skip to content

Commit

Permalink
Merge pull request #137 from kvij/query_fixes
Browse files Browse the repository at this point in the history
Fix Findable trait due to breaking changes in Exact REST API
  • Loading branch information
stephangroen authored May 22, 2017
2 parents e9f058f + 8d02072 commit d5d86c8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Picqer/Financials/Exact/Query/Findable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ trait Findable

public function find($id)
{
$result = $this->connection()->get($this->url, [
'$filter' => $this->primaryKey . " eq guid'$id'"
$records = $this->connection()->get($this->url, [
'$filter' => $this->primaryKey . " eq guid'$id'",
'$top' => 1, // The result will always be 1 but on some entities Exact gives an error without it.
]);

$result = isset($records[0]) ? $records[0] : null;
return new self($this->connection(), $result);
}

Expand Down Expand Up @@ -44,7 +46,12 @@ public function findId($code, $key='Code'){
}

$filter = sprintf("$key eq $format", $code);
$request = array('$filter' => $filter, '$top' => 1, '$orderby' => $this->primaryKey);
$request = [
'$filter' => $filter,
'$top' => 1,
'$select' => $this->primaryKey,
'$orderby' => $this->primaryKey,
];
if( $records = $this->connection()->get($this->url, $request) ){
return $records[0][$this->primaryKey];
}
Expand Down

0 comments on commit d5d86c8

Please sign in to comment.