Hi everybody,
i'm very confused about saving and editing HABTM relationship and
probably a full example in the manual could help...
I've correctly created the models and MySQL tables.
My relationship is: an Employment has and belongs to many Employees.
I've inserted some data in the database by hand and i'd like to create
the edit action, but i'm failing in it.
I attach my example, it doesn't actually work but i can't understand
where are the errors :(
## employees_controller.php ##
[..]
public function edit($id = null)
{
$this->Employee->id = $id;
if(empty($this->data))
{
$this->set('employments', $this->Employment->findAll());
$this->data = $this->Employee->read();
}
else
{
if($this->Employee->save($this->data['Employee']))
$this->flash(__("employee_updated" ,true),
"/employee/index");
[..]
}
}
[..]
## edit.ctp ##
[..]
echo $form->select('Employment.Employment',
$employments,null,array('multiple'=> true));
[..]
## employee.php ##
class Employee extends AppModel
{
var $name = 'Employee';
var $hasAndBelongsToMany = array(
'Employment' =>
array('className'
=> 'Employment',
'joinTable'
=> 'employees_employments',
'foreignKey'
=> 'employee_id',
'associationForeignKey' =>
'employment_id',
'conditions'
=> '',
'order' => '',
'limit' => '',
'uniq' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
var $validate = array(
'surname' => array(
'allowEmpty' => false ),
'name' =>
array( 'allowEmpty' => false ),
'fiscal_code' => array( 'rule' =>
'alphaNumeric', 'allowEmpty' =>
false ),
'birth_date' => array( 'rule' =>
'date', 'allowEmpty' =>
false ),
'email' =>
array( 'rule' => array('email', true), 'allowEmpty'
=> false),
'recruitment_date' => array( 'rule' => 'date',
'allowEmpty' =>
false )
);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---