I am trying to combine two join fields as a valueField in a dropdown combo. After checking https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#finding-key-value-pairs and How do I create a keyValue pair (display field) by combining/having two fields in CakePHP 3? I tried the following:
This works:
$authorities = $this->Books->Authorities->find('list', [
'valueField' => 'author.name'])
->contain(['Authors', 'AuthorTypes']);
This works too:
$authorities = $this->Books->Authorities->find('list', [
'valueField' => 'author_type.name'])
->contain(['Authors', 'AuthorTypes']);
But this doesn't:
$authorities = $this->Books->Authorities->find('list', [
'valueField' => function ($row) {
return $row['author.name'] . ' - ' . $row['author_type.name'];
}])
->contain(['Authors', 'AuthorTypes']);
I can't understand why. Any ideas? :)