if ($returnType) {
$returnObj = $response->getResponseAsObject($returnType);
}
return $returnObj;
If the `returnType` is anything but false, `ODataResponse::getResponseAsObject` and returns an **array** of object. This array then gets correctly mapped to a collection.
The problem is that everything assumes that `ODataRequest::execute` returns an array of object, but that is not the case when `returnType` is false
### Proposed solution
Wrap the raw response in an array when `returnType` is false
PR incoming
How to reproduce
ODataResponse
objects from queries :print_r($result)
:Cause
Here is the data flow and the associated return value types (read return types from bottom up)
Query\Builder::find
whereKey
returns aBuilder
first
returns anODataRequest
Query\Builder::first
Query\Builder::get
returns anIlluminate/Collection
containing anODataRequest
in first position.Illuminate\Collection::first
returns the first element of the collectionQuery\Builder::get
Query\Builder::runGet
returns aODataReponse
Processor::processSelect
is the identitfy function and returns the sameODataResponse
Illuminate\collect
takes theODataResponse
and insert its field in a new collection. The first field of anODataResponse
is the associated request.Query\Builder::runGet
: returns anODataResponse
ODataClient::get
: returns anODataResponse
ODataClient::request
: returns anODataResponse
ODataRequest::execute
$returnType = is_null($this->returnType) ? Entity::class : $this->returnType;
if ($returnType) { $returnObj = $response->getResponseAsObject($returnType); } return $returnObj;