Skip to content

Commit

Permalink
Merge pull request #505 from it-can/firstWithFilters
Browse files Browse the repository at this point in the history
add filter options to first() method
  • Loading branch information
stephangroen authored Sep 30, 2021
2 parents 7773508 + c6cebf4 commit 8b92410
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Picqer/Financials/Exact/Query/Findable.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,20 @@ public function filter($filter, $expand = '', $select = '', $system_query_option
*
* @return \Picqer\Financials\Exact\Model|null
*/
public function first()
public function first($filter = '', $expand = '', $select = '', $system_query_options = null, array $headers = [])
{
$results = $this->filter('', '', '', ['$top'=> 1]);
$query_options = [
'$top'=> 1,
];

if (is_array($system_query_options)) {
// Remove this option, we only want 1 record
unset($system_query_options['$top']);

$query_options = array_merge($query_options, $system_query_options);
}

$results = $this->filter($filter, $expand, $select, $query_options, $headers);
$result = is_array($results) && count($results) > 0 ? $results[0] : null;

return $result;
Expand Down

0 comments on commit 8b92410

Please sign in to comment.