That looks ok to me; Cake will attempt to update a record with the primary key of id
when it's manually set like that.
Do a search in your table with the supposedly "unique" data; and see if any other result can be found. It's possible you have duplicate data that was in use before you introduced the isUnique
validation rule.
Are you doing this update within a loop?
You could possibly try changing the on
validation rule in your model to create
, preventing it from triggering on an update; but I'm not sure that should be necessary; plus you could then update
a record with duplicate information, defeating the purpose!
var $validate = array(
'fieldName1' => array(
'rule' => 'isUnique',
'required' => true,
'allowEmpty' => false,
'on' => 'create', // here
'last' => false,
'message' => 'Your Error Message'
)
);