I'm trying to populate a form model with also his associated models.
Main model : Pronostic
Child model (hasMany) : Prono
Controller :
$Pronostic = $this->Pronostic->find('first',array('recursive'=>1,'conditions'=>array('Pronostic.user_id'=>$this->Auth->user('id'),'Pronostic.id'=>$this->request['named']['id'])));
[...]
$this->request->data = $Pronostic;
debug($Pronostic) :
array(
'Pronostic' => array(
'user_id' => '12',
'id' => '2',
'name' => 'My nanme',
'content' => '',
'star' => '5',
'active' => '0',
'slug' => '',
'created' => '2015-02-11 20:51:26',
'modified' => '2015-02-12 07:17:57'
),
'Prono' => array(
(int) 0 => array(
'user_id' => '12',
'sport_id' => '0',
'bookmaker_id' => '0',
'event_id' => '2',
'pronostic_id' => '2',
'league_id' => '0',
'id' => '20',
'created' => '2015-02-11 20:57:56',
'modified' => '2015-02-11 20:57:56',
'bet' => 'bet1',
'odd' => '12',
'amount' => '12',
'level' => '0'
),
(int) 1 => array(
'user_id' => '12',
'sport_id' => '0',
'bookmaker_id' => '0',
'event_id' => '1',
'pronostic_id' => '2',
'league_id' => '0',
'id' => '19',
'created' => '2015-02-11 20:57:56',
'modified' => '2015-02-11 20:57:56',
'bet' => 'bet2',
'odd' => '24',
'amount' => '24',
'level' => '0'
)
)
)
View :
echo $this->Form->create('Pronostic', array('class'=>'form-horizontal widget-login'));
echo $this->Form->input('Pronostic.name',array('label'=>false,'class'=>'form-control'));
echo $this->Form->input('Pronostic.Prono.'.$Prono['Prono']['id'].'.id',array('value'=>$Prono['Prono']['id']));
echo $this->Form->input('Pronostic.Prono.'.$Prono['Prono']['id'].'.bet',array('label'=>false,'class'=>'form-control'));
Pronostic.name is correctly populate, but not Pronostic.
Someone can help me?
Thanks