Issue Feature Closed

#81631foreign_match_fields should allow a not-equal option

Johannes Schlier 06/20/17, 14:25 updated 11/14/26, 20:17

Description

Foreign_match_fields are really useful to differentiate cases when using the same foreign table.
One case that I think should also be considered is the following:

Suppose you have a table ‘tx_something’ and you have a type field that might go up to 100 or so.
Now you want to do something special with type 1 (overriding some values in the TCA for example). All the other types should still be available, but in another field that doesn’t have the overridden TCA.

Without a foreign_match_field the records with type 1 would show up in the general field as well.
The way foreign_match_fields currently works would require a new field for every non-special type, which is really unnecessary and not great should new types be added at a later point.

So I would suggest something like the following:

'specialField' => [
  'config' => [
    'type' => 'inline',
    'foreign_table' => 'tx_something',
    'foreign_match_fields' => [
        'type' => 1
    ],
    'overrideChildTca' => [
        'val1' => 'foo',
        'val2' => 'bar',
        'val3' => 'foobar'
    ]
  ]
],
'generalField' => [
  'config' => [
    'type' => 'inline',
    'foreign_table' => 'tx_something',
    'foreign_match_fields' => [

      'type' => '!1'

    ]
]

This could then be parsed by the RelationHandler, which would replace the ‘eq’ in the where expression it’s constructing with a ‘neq’ and deliver the wanted results.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 1

  1. Georg Ringer commented and changed status New Closed 11/14/26, 20:17

    Hi Johannes,

    thanks for the detailed description and for the example.

    I am closing this issue as there has been no further interest in the last years and because of a design concern: foreign_match_fields is used for two purposes. It restricts the records which are read (RelationHandler builds equality conditions from it), and it also provides the field values which are written to a child record when it is created or attached to the parent. A negated value such as '!1' can be used as a filter, but there is no value to write, so the same option would behave differently depending on the direction. That makes the option harder to understand and to document.

    For the described case, a dedicated field or table for the special type, or overrideChildTca together with a separate type value, are the more explicit options.

    If this is still valid for you in v14, please open a new issue and provide information how to reproduce it. Thanks!