Skip to content

Commit

Permalink
Add includedFields parameter in DoctrineListRepresentationFactoryInte…
Browse files Browse the repository at this point in the history
…rface (#3)
  • Loading branch information
niklasnatter authored Mar 31, 2020
1 parent 16b279a commit dde5584
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ListRepresentation/DoctrineListRepresentationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public function __construct(
/**
* @param mixed[] $filters
* @param mixed[] $parameters
* @param string[] $includedFields
*/
public function createDoctrineListRepresentation(
string $resourceKey,
array $filters = [],
array $parameters = []
array $parameters = [],
array $includedFields = []
): PaginatedRepresentation {
/** @var DoctrineFieldDescriptor[] $fieldDescriptors */
$fieldDescriptors = $this->fieldDescriptorFactory->getFieldDescriptors($resourceKey);
Expand All @@ -68,6 +70,10 @@ public function createDoctrineListRepresentation(
$listBuilder->where($fieldDescriptors[$key], $value);
}

foreach ($includedFields as $field) {
$listBuilder->addSelectField($fieldDescriptors[$field]);
}

$items = $listBuilder->execute();

// sort the items to reflect the order of the given ids if the list was requested to include specific ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ interface DoctrineListRepresentationFactoryInterface
/**
* @param mixed[] $filters
* @param mixed[] $parameters
* @param string[] $includedFields
*/
public function createDoctrineListRepresentation(
string $resourceKey,
array $filters = [],
array $parameters = []
array $parameters = [],
array $includedFields = []
): PaginatedRepresentation;
}

0 comments on commit dde5584

Please sign in to comment.