I have two model in belongs to association, in cake php 3.4, left the namespaces and use there are:
the first:
class TipoSessioniTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('gst_tipo_sessioni');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
}
…
}
The second
class SessioneTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->setTable('gst_sessioni');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('TipoSessioni', [
'foreignKey' => 'id_tipo_sessioni',
'joinType' => 'INNER'
]);
}
…
}
I would like to get a list grouped , i try with this code
$query = $this->find('list', [
'keyField' => 'sede',
'valueField' => 'TipoSessioni.contesto',
'groupField' => 'id'
]);
$query->contain('TipoSessioni');
$query->where(['TipoSessioni.contesto' => AppConst::cContestoSessione, 'Sessione.attiva' => 1, 'Sessione.pubblica' => 1]);
$data = $query->toArray();
and i get this result:
[
(int) 249 => [
‘CES’ => null
],
(int) 254 => [
‘RIM’ => null
],
(int) 256 => [
‘BOL’ => null
],
(int) 253 => [
‘FOR’ => null
]
]
Ie the value from the TipoSessioni.pagamenti field is not retrieved.
The find method list in association belongs to doesn’t retrieve values of the fields from related table.
This behaviour also happen in cake php 2.
In documentation don’t talk about it.
If i make the find all i get all fields but i have to do some workaround to get my representation needed.