Thursday, May 30, 2013

Re: Foreach saveField fails

did you change id to CHAR(36) in mysql ?

you could 

alter table by adding a temporary 'newid' field 

$this->saveField('newid', $new);

once looks good remove id, rename newid to id, add indexes etc... 

or

UPDATE entries SET id = uuid();


Careful if you have related tables with foreign key, as those need to be updated as well..


Andras Kende


On May 30, 2013, at 11:38 AM, Advantage+ <movepixels@gmail.com> wrote:

I am switching up a table 'id' field and simple doing a find all, generate a UUID, and try to update the field foreach but all its doing is creating new empty records.
 
 
foreach($this->find('all') as $entry) {
                $new = String::uuid();
                $this->id = $entry['Entry']['id'];
                //debug($this->id);
                $this->saveField('id', $new);
}
 
If I remove the commented out debug() I get all the original id's but it simply not update the record.
 
Even tried $this->updateAll(array('Entry.id' => $new), array('Entry.id' => $entry['Entry']['id']));
 
But that does not seem to work eiter.
 
Any ideas?
 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
--- 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: