contao/import — Issue #3489: `foreignKey` option for `pid` doesn't work as expected
Author: DyaGa
Created: 2011-11-29 21:40:53+00:00
State: open
Labels: backend, Defect, Invalid

**Example**
I have table `tl_order`. `tl_member` is a parent table for my Order table.

In `[custom_module]/dca/tl_order.php`:

```
$GLOBALS['TL_DCA']['tl_fk_order'] = array
(
// Config
'config' => array (
[...]
'ptable' => 'tl_member',

[...]

// Fields
'fields' => array
(
'pid' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_fk_order']['pid'],
'exclude' => true,
'inputType' => 'input',
'filter' => true,
'foreignKey' => 'tl_member.username',
'eval' => array('mandatory'=>true, 'rgxp'=>'digit', 'nospace'=>true, 'readonly'=>true)
),

[...]
)
```

As you can see in attached image (`img-01`) in Filter block it shows member `id` field values, not field `username` as expected.

**Partial solution**
I found, that `filterMenu()` method of `DC_Table` class doesn't load DCA container, but it uses the code of getting parent table fields label (see DC_Table.php from line 4480):

```
protected function filterMenu()
{
[...]
// Get the name of the parent record
if ($field == 'pid')
{
$showFields = $GLOBALS['TL_DCA'][$this->ptable]['list']['label']['fields'];
[...]
```

So, after adding code

```
$this->loadDataContainer($this->ptable);
```

to `filterMenu()` method at line 4473 it solves the problem, but not generally (see attached image `img-02`). Now it shows only member `firstname` field label, but `tl_member.username` expected.

[Download the attachments](http://www.contao.org/tl_files/tickets/3489.zip "Download the attachments of this ticket")

--- _Originally created on September 19th, 2011, at 04:30pm (ID 3489)_