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?

Comments

marcus_w created an issue. See original summary.

e0ipso’s picture

Thanks 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?

marcus_w’s picture

I 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.

marcus_w’s picture

It seems we could also check if it is an entity_reference field, changing line 73-78 to

      if (
        empty($definitions[$field_name]) ||
        $definitions[$field_name]->getType() != 'entity_reference'
      ) {
        return $external_field_name;
      }

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.

e0ipso’s picture

Assigned: Unassigned » e0ipso
e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new5.74 KB

This was a good catch. I did my functional testing with the link field type (shipped with core) while debugging. Unit automated tests were added.

e0ipso’s picture

Added functional testing. Merging if green.

  • e0ipso committed 4859b42 on 8.x-1.x
    fix(Query) Allow querying compound fields (#2834896 by e0ipso)
    
e0ipso’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.