Skip to content

(WIP) Fix the default sorting of associated entities#5345

Open
javiereguiluz wants to merge 1 commit into
EasyCorp:4.xfrom
javiereguiluz:fix_4875
Open

(WIP) Fix the default sorting of associated entities#5345
javiereguiluz wants to merge 1 commit into
EasyCorp:4.xfrom
javiereguiluz:fix_4875

Conversation

@javiereguiluz
Copy link
Copy Markdown
Collaborator

Fixes #4875.

It's WIP because I still see some bugs.

@javiereguiluz javiereguiluz added this to the 4.x milestone Jul 23, 2022
Comment on lines +160 to +177
if ($entityDto->isAssociation($field->getProperty())) {
$associatedProperties = explode('.', $field->getProperty());
for ($i = 0; $i < \count($associatedProperties); $i++) {
$property = $associatedProperties[$i];
if (!$entityDto->hasProperty($property)) {
return false;
}

// try to get the entity associated to the property, except for the last property
if (isset($associatedProperties[$i + 1])) {
$propertyMetadata = $entityDto->getPropertyMetadata($property);
$targetEntity = $propertyMetadata->get('targetEntity');
$entityDto = $this->entityFactory->create($targetEntity);
}
}

return true;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the logic to handle associations is re implemented in many places and we should find a way to implement it in a reusable way across searching, filtering and ordering.

Another implementation supporting embedded is here:

private function getSearchablePropertiesConfig(QueryBuilder $queryBuilder, SearchDto $searchDto, EntityDto $entityDto): array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setDefaultSort indicator (arrow) not shown for nested associations

2 participants