{"action":"opened","issue":{"url":"https://api.github.com/repos/api-platform/core/issues/2109","repository_url":"https://api.github.com/repos/api-platform/core","labels_url":"https://api.github.com/repos/api-platform/core/issues/2109/labels{/name}","comments_url":"https://api.github.com/repos/api-platform/core/issues/2109/comments","events_url":"https://api.github.com/repos/api-platform/core/issues/2109/events","html_url":"https://github.com/api-platform/core/issues/2109","id":342262354,"node_id":"MDU6SXNzdWUzNDIyNjIzNTQ=","number":2109,"title":"OrderFilter on nested entity seems KO","user":{"login":"BatsaxIV","id":1379286,"node_id":"MDQ6VXNlcjEzNzkyODY=","avatar_url":"https://avatars2.githubusercontent.com/u/1379286?v=4","gravatar_id":"","url":"https://api.github.com/users/BatsaxIV","html_url":"https://github.com/BatsaxIV","followers_url":"https://api.github.com/users/BatsaxIV/followers","following_url":"https://api.github.com/users/BatsaxIV/following{/other_user}","gists_url":"https://api.github.com/users/BatsaxIV/gists{/gist_id}","starred_url":"https://api.github.com/users/BatsaxIV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BatsaxIV/subscriptions","organizations_url":"https://api.github.com/users/BatsaxIV/orgs","repos_url":"https://api.github.com/users/BatsaxIV/repos","events_url":"https://api.github.com/users/BatsaxIV/events{/privacy}","received_events_url":"https://api.github.com/users/BatsaxIV/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-18T10:07:21Z","updated_at":"2018-07-18T10:07:21Z","closed_at":null,"author_association":"NONE","body":"Hi guys,\r\n\r\nAn entity _User_ has a relation with another entity _Conversation_.\r\nIf I use the **OrderBy** filter on _conversation.createdAt_ the User without a _Conversation_ will be excluded from the results.\r\n\r\n```php \r\n@ApiFilter(OrderFilter::class, properties={\"conversation.createdAt\": \"ASC\" }})\r\n```\r\nSearching through github I've found : \r\n\r\n- [This first issue](https://github.com/api-platform/core/issues/363) with [the associated fix](https://github.com/api-platform/core/pull/367/files)\r\n\r\n- The ability to use null comparison with [this PR](https://github.com/api-platform/core/pull/838) \r\n\r\nSo I transform my filter to : \r\n```php \r\n@ApiFilter(OrderFilter::class, properties={\"conversation.createdAt\": { \"nulls_comparison\": OrderFilter::NULLS_SMALLEST, \"default_direction\": \"ASC\" }})\r\n```\r\n\r\n\r\nFull of trust :+1: , I press Send button on postman and... still excluded :disappointed: \r\n\r\nDigging a bit I see that the [OrderFilter](https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Filter/OrderFilter.php#L149) call a specific method for join relation : \r\n```php \r\nlist($alias, $field) = $this->addJoinsForNestedProperty($property, $alias, $queryBuilder, $queryNameGenerator, $resourceClass);\r\n```\r\n\r\nThen on the [AbstractFilter](https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Filter/AbstractFilter.php#L325) : \r\n```php \r\n$alias = QueryBuilderHelper::addJoinOnce($queryBuilder, $queryNameGenerator, $parentAlias, $association);\r\n```\r\n\r\nAnd finally in the [QueryBuilderHelper](https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Util/QueryBuilderHelper.php#L44) : \r\n```php \r\nif (Join::LEFT_JOIN === $joinType || QueryChecker::hasLeftJoin($queryBuilder)) {\r\n    $queryBuilder->leftJoin($query, $associationAlias, $conditionType, $condition);\r\n} else {\r\n    $queryBuilder->innerJoin($query, $associationAlias, $conditionType, $condition);\r\n}\r\n```\r\nThere is no **$joinType** send and the **QueryCheck::hasLeftJoin** returns false, so an _innerJoin_ is made instead of a _leftJoin_.  \r\nIf I forced a _leftJoin_, the results are ok.\r\n\r\nAm I missing something or is there a problem?\r\n\r\nThanks,\r\nJérémy."}}
{"actor":{"display_login":"BatsaxIV"}}