Cannot edit User due to unique rule, it must be possible to update user details
in app/Model/User.php
public $validate = array(
'Username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Please choose a username'
),
'unique' => array(
'rule' => 'isUnique',
'message' => 'The username you have chosen has already been registered'
)
)
);
- Is there any way we could disable this rule for editing the current record unless the name was changed? i.e. it won't update the username unless it was changed
- This rule currently stops the record from being edited so I cannot update disabled in CakePHP for example
- This rule stops the REST calls from updating the record as well
- We could override or hook into the edit for that record and only request an update if what was posted differs from what was in the database in app/Model/User.php
public function save ($data = null, $validate = true, $fieldList = array())
{
$record = $this->find('first', array('conditions' => array('UserID' => $this->id)));
// If the Username was unchanged then unset it
if ($data['User']['Username'] == $record['User'][Username]) {
unset($data['User']['Username']);
}
}