i have the following code
public function setNewDefaultImgByHash($parameters){
$itemImgDefaultOld=ItemImg::findFirst(
array("item_id = ?1 and default = ?2",
"bind"=>array(1=>$this->id,2=>1)));
if($itemImgDefaultOld){
$itemImgDefaultOld->default=0;
$itemImgDefaultOld->save();
}
$itemImgDefaultNew=ItemImg::findFirst(
array("item_id = ?1 and hash = ?2",
"bind"=>array(1=>$this->id,2=>$parameter)));
if($itemImgDefaultNew){
$itemImgDefaultNew->default=1;
$itemImgDefaultNew->save();
}
return;
}
What im trying to do is get the old default set it to 0 then get the new img by a hash and set it as the new default. Checking the general query log from mysql it does the following
430 Query SELECT `item_img`.`item_id`, `item_img`.`hash`, `item_img`.`img_type`, `item_img`.`route`, `item_img`.`default` FROM `item_img` WHERE `item_img`.`item_id` = '3' AND `item_img`.`default` = 1 LIMIT 1
430 Query UPDATE `item_img` SET `img_type` = 'image/jpeg', `route` = './img/item/309e970fce75e4666b29113c6a57b967b', `default` = 0 WHERE `item_id` = '3' AND `hash` = '318919a3792c13a518987f07ceff1536d'
430 Query SELECT `item_img`.`item_id`, `item_img`.`hash`, `item_img`.`img_type`, `item_img`.`route`, `item_img`.`default` FROM `item_img` WHERE `item_img`.`item_id` = '3' AND `item_img`.`hash` = NULL LIMIT 1
the first select is ok but the update is all wrong and the following select is also wrong. Ive ben trying for hours to get it to work but no luck so far.