find (list) devuelve varias opciones en blanco, find (all) devuelve datos correctos pero formateados con {
AvadiariesTable.php
$this->belongsTo('AlumnesGrups', [
'foreignKey' => 'alumnes_grup_id',
'joinType' => 'INNER'
AlumnesGrupsTable.php
$this->belongsTo('Alumnes', [
'foreignKey' => 'alumne_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Grups', [
'foreignKey' => 'grup_id',
'joinType' => 'INNER'
]);
¿Por qué es esto en AvadiariesController.php:
public function add()
{
$avadiary = $this->Avadiaries->newEntity();
if ($this->request->is('post')) {
$avadiary = $this->Avadiaries->patchEntity($avadiary, $this->request->data);
$avadiary->user_id = $this->Auth->user('id');
if ($this->Avadiaries->save($avadiary)) {
$this->Flash->success(__('The avadiary has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The avadiary could not be saved. Please, try again.'));
}
}
$alumnesGrups = $this->Avadiaries->AlumnesGrups->find('all', [
'fields' => ['Alumnes.name'],
'contain' =>['Alumnes', 'Grups'],
'conditions' => ['Grups.id =' => 1],
'order' => ['Alumnes.name' => 'ASC']
]);
$this->set(compact('avadiary', 'alumnesGrups'));
$this->set('_serialize', ['avadiary']);
}
devolviendo datos correctos pero formateados así:
{"Alumnes": {"nombre": "Angela Smith"}}?
¿Cómo puedo obtener Angela Smith? Si cambio find (all) por find (list), el cuadro de selección se completa con varias opciones en blanco.
¡Gracias!