Update: I managed to get the 'multiple' rule working, but I am having
to force it in my controller action as follows
Role Model:
validate = array(
'Role' => array(
'rule' => array('multiple', array('min'=>1)),
'message' => 'If approved, select one or more roles'
)
);
Staff Controller:
function edit($id = null) {
if (!empty($this->data)) {
$this->Staff->Role->set($this->data); // pass data to Role model,
doesn't check rule without this
$this->data['Staff']['modifier_id'] = $this->authUser['User']
['id'];
$this->data['Person']['modifier_id'] = $this->authUser['User']
['id'];
if ($this->Staff->saveAll($this->data, array('validate'=>'first'))
&& $this->Staff->Role->validates()) {
$this->Session->setFlash('Staff updated');
$this->redirect('view/'.$this->Staff->id);
} else {
$this->Session->setFlash('Staff not updated, correct errors and
resubmit');
}
} else {
$this->data = $this->Staff->find('first', array(
'conditions' => array('Staff.id'=>$id),
'contain' => array('Person'=>array('Organisation'),'Role')
));
$this->data['Scheme']['id'] = $this->data['Person']['Organisation']
['scheme_id'];
}
$this->__formData();
}
Problem with this is it's running validation for the Staff->saveAll()
separately from Role->validates() generating independent $this-
>validationErrors arrays so I get either the errors from one check OR
the other, not both.
Can anyone advise how I can run this so all errors are properly added
to $this->validationErrors?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---