I need to change the value of two rows in the order
field of my database. This field is unique.
What I tried:
Storing the value of both items in a PHP variable,
Setting the first row's field value to
NULL
(nulls are accepted in the field),Setting the value of the second row's field to the value that was held on the first row,
Setting the first row's field value to the original second row field value.
It doesn't work, since I am getting a "dupplicate entry" error when executing the order change. I can't seem to find out how to do this using CakePHP.
Here is the code that I have written (even though it's not functionnal):
if ($second_row) {
$next = $second_row['Immeuble']['order'];
$prev = $first_row['Immeuble']['order'];
$this->Immeuble->id = $first_row_id;
$this->Immeuble->saveField('order', 'null');
$this->Immeuble->id = $second_row['Immeuble']['id'];
$this->Immeuble->saveField('order', $prev);
$this->Immeuble->id = $first_row_id;
$this->Immeuble->saveField('order',$next);
}