Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
27pchrisl committed Oct 31, 2023
1 parent 975d680 commit 4be3580
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/Drivers/EloquentEntitySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,18 @@ public function delete(PropertyValue $key): void
public function query(): Generator
{
$builder = $this->getBuilder();
$builder->select('*');

$properties = $this->getSelectedProperties();

$key = $this->getType()->getKey();

if ($key && !$properties[$key]) {
$properties[] = $key;
}

$builder->select($properties->map(function (Property $property) {
return $this->getPropertySourceName($property);
}));

if ($this->navigationSource) {
/** @var Entity $sourceEntity */
Expand Down
14 changes: 1 addition & 13 deletions src/Drivers/SQLEntitySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,7 @@ public function getResultExpression(): SQLExpression
*/
protected function getColumnsToQuery(): array
{
$properties = $this->getType()->getDeclaredProperties();

$select = $this->getSelect();

if ($select->hasValue() && !$select->isStar()) {
$selectedProperties = $select->getCommaSeparatedValues();

foreach ($properties as $property) {
if (!in_array($property->getName(), $selectedProperties)) {
$properties->drop($property);
}
}
}
$properties = $this->getSelectedProperties();

$key = $this->getType()->getKey();

Expand Down
25 changes: 25 additions & 0 deletions src/EntitySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Flat3\Lodata\Helper\Gate;
use Flat3\Lodata\Helper\JSON;
use Flat3\Lodata\Helper\ObjectArray;
use Flat3\Lodata\Helper\Properties;
use Flat3\Lodata\Helper\PropertyValue;
use Flat3\Lodata\Helper\PropertyValues;
use Flat3\Lodata\Helper\Url;
Expand Down Expand Up @@ -1205,6 +1206,30 @@ protected function toEntity(array $record, $entityId = null): Entity
return $entity;
}

/**
* Get the properties generated using the $compute system query option
* @return Properties
*/
public function getComputedProperties(): Properties
{
return $this->getCompute()->getProperties();
}

/**
* Get the properties requsted using the $select system query option
* @return Properties
*/
public function getSelectedProperties(): Properties
{
if (!$this->getSelect()->hasValue() || $this->getSelect()->isStar()) {
return $this->getType()->getDeclaredProperties();
}

return $this->getType()->getDeclaredProperties()->filter(function (Property $property) {
return in_array($property, $this->getSelect()->getCommaSeparatedValues());
});
}

/**
* Recursively convert this complex value to a nested PHP array of key/value pairs
* @return array Record
Expand Down

0 comments on commit 4be3580

Please sign in to comment.