I'm using the address module, which adds a compound field to the entity. I want to filter on the field_address_locality column of the address field table. This however is restricted by what seems to be the resolveInternal() function. That function decides that having a dot in the filter field means it's an external field. Which in this case isn't true.
Shouldn't the filter fieldname just contain .entity. in case you want to filter by any external field?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2834896--interdiff--6-7.txt | 4.55 KB | e0ipso |
| #7 | 2834896--resolve-internal-complex-fields--7.patch | 10.29 KB | e0ipso |
| #6 | 2834896--resolve-internal-complex-fields--6.patch | 5.74 KB | e0ipso |
Comments
Comment #2
e0ipsoThanks for reporting @marcus_w. It seems you have done some debugging. Do you have any patch that you can share so someone else can follow your findings?
Comment #3
marcus_w commentedI did very little debugging, but the problem seems to be that on the Drupal\jsonapi\Context\FieldResolver::resolveInternal() function, the check is only on a dot. If a dot is found, it is assumed to be an external field.
In the Entity Query API, a .entity. part is needed for this external fields, therefore, if a dot is found, it is essentially replaced with .entity.. This means that querying on internal compound fields isn't possible. I think the query syntax should be the same as the Entity API query syntax, meaning that if filtering needs to be done on external fields, the .entity. should be provided in the request.
That would mean an API change for the module, so I haven't created a patch, as I don't know if it really is the best solution.
Comment #4
marcus_w commentedIt seems we could also check if it is an entity_reference field, changing line 73-78 to
Fixes the issue, but leaves the API intact. Though I think checking if it is not external is the other way around. We should check if the field is internal, and if not, retrieve the external field.
Comment #5
e0ipsoComment #6
e0ipsoThis was a good catch. I did my functional testing with the link field type (shipped with core) while debugging. Unit automated tests were added.
Comment #7
e0ipsoAdded functional testing. Merging if green.
Comment #9
e0ipso