Ok, after spent some hours reading once and once the docs I found the error and leave here the solution, the definition of public $hasMany is wrong and this is the right way:

public $hasMany = array(
        'Education' => array(
        'className' => 'Education',
        'foreignKey' => 'candidate_id',
        'dependent' => true
        ),
        'Experience' => array(
        'className' => 'Experience',
        'foreignKey' => 'candidate_id',
        'dependent' => true
        ),
        'Attachment' => array(
        'className' => 'Attachment',
        'foreignKey' => 'candidate_id',
        'dependent' => true
        )
);

Now my problem is another, when I try to get the associated records from tables Education, Experienca and Attachement it's not showed and I can't find the error, any help?

Cheers and thanks in advance

On 2/24/2012 7:55 AM, [email protected] wrote:
Hi every:
I have a table called Information with some relations 1:m with some others
tables. The model for Information table is as follow:
<?php
App::uses('AppModel', 'Model');
class Information extends AppModel {
public $useTable = 'informations';
public $displayField = 'name';
public $validate = array(
'name' =>  array(
'notempty' =>  array(
'rule' =>  array('notempty'),
'message' =>  'The field name can not be empty',
),
),
'lastname' =>  array(
'notempty' =>  array(
'rule' =>  array('notempty'),
'message' =>  'The field lastname can not be empty',
),
),
'email' =>  array(
'email' =>  array(
'rule' =>  array('email'),
'message' =>  'The email address is not correct',
),
),
);

public $belongsTo = array(
'Country' =>  array(
'className' =>  'Country',
'foreignKey' =>  'countries_id',
'conditions' =>  '',
'fields' =>  '',
'order' =>  ''
)
);
  public $hasMany = array(
'Educations' =>  array(
'className' =>  'Education',
'foreignKey' =>  'candidate_id',
'dependent' =>  true
),
'Experiences' =>  array(
'className' =>  'Experience',
'foreignKey' =>  'candidate_id',
'dependent' =>  true
),
'Attachments' =>  array(
'className' =>  'Attachment',
'foreignKey' =>  'candidate_id',
'dependent' =>  true
)
);
}

Then in my controller InformationController I have this code for add a new
information:
public function add() {
if ($this->request->is('post')) {
$this->Information->create();
if ($this->Information->save($this->request->data)) {
$this->Session->setFlash(__('The information has been saved'));
$this->redirect(array('action' =>  'index'));
} else {
$this->Session->setFlash(__('The information could not be saved. Please,
try again.'));
}
}
$countries = $this->Information->Country->find('list');
$this->set(compact('countries'));
}

But surprise the record is created but empty, why?

Ing. Reynier Pérez Mira
http://reynierpm.site90.com/


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to