Welcome Guest, Not a member yet? Register   Sign In
Active Record; adding to an existing value?
#1

[eluser]_asdf[/eluser]
Using the activerecord class, I'm trying to update an existing value (think post count, etc) by N.

In theory, it'd go like:
Code:
$this->db->set('columnName', 'columnName + 1');
$this->db->where('columnId', $id);

But of course, the AR itself escapes it, so you end up with a query like
Code:
UPDATE TableName SET columnName = 'columnName + 1' WHERE columnId = '1'

Then I figured maybe I could do it the way one does where comparisons, like so:
Code:
$this->db->set('columnName = columnName + ', 1);
but that produces queries like:
Code:
UPDATE TableName SET columnName = columnName + = 1 WHERE columnId = '1'

Is there a way to get this to produce the correct query, eg:
Code:
UPDATE TableName SET columnName = columnName + 1 WHERE columnId = '1'
or do I really need to do it the non-ActiveRecord way? (ick). It'd be the only place in the application where I've had to roll normal SQL, so I'd like to avoid it for consistency, if possible.

Any help & Suggestions most appreciated.

(Its been ages since I used CI, but its so nice to be back. Aside from this one sticking issue.)
#2

[eluser]xwero[/eluser]
version 1.6 (SVN) solves this issue with an extra parameter
Code:
$this->db->set('columnName', 'columnName + 1',false);




Theme © iAndrew 2016 - Forum software by © MyBB