Hi everybody,

I have a quick question that bugs me each time I run into it in a project,
and then I promptly forget about it.  It is an easy fix, but it is such
common functionality that I feel there must be some way to do it within
built in functions rather then a custom query.

The issue is incrementing a table field without grabbing the previous value,
using MySQL's default function `tablefield` = `tablefield` + 1 .

example:

$this->Item->query('UPDATE `items` SET `flags` = `flags`+1 WHERE
`items`.`id` = ' . $id);

I have tried pretty much every way I can think of with model->saveField to
accomplish this through cake, but I can't get it to work.

First I set the id with $this->Item->id = $id
After that I have tried

$this->Item->saveField('flags','+1');
$this->Item->saveField('flags',' +1');
$this->Item->saveField('flags', 'flags+1');
$this->Item->saveField('flags', '`flags`+1');

So... is there a way to do this with 1 query within cake? I like to have as
few custom queries as possible within my application.

Thanks for any tips,

who knows, if it isn't built in maybe I will be able to make my first
contribution to the Core!

Dave

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=.


Reply via email to