Added inc/decrement functionality to the Model

Sure beats incrementing the variable then setting it! Usage: $model->record['column'] = '++'; // or '--'. Only works with single row updates at the moment. May expand into allowing a variable step to be defined (+10 or ++10 or something... I say that cause I think the double character is a bit safer since you could in theory set a value to -10000 and not want it to decrement by 10k)
This commit is contained in:
Josh Sherman 2012-12-30 12:21:49 -05:00
parent c19ac9fbae
commit fe0fd407cf
2 changed files with 22 additions and 2 deletions

View file

@ -1301,7 +1301,17 @@ class Model extends Object
$sql .= ', '; $sql .= ', ';
} }
$sql .= $column . ' = ?'; $sql .= $column . ' = ';
if (in_array($value, array('++', '--')))
{
$sql .= $column . ' ' . substr($value, 0, 1) . ' ?';
$value = 1;
}
else
{
$sql .= '?';
}
} }
else else
{ {

12
jar.php
View file

@ -5560,7 +5560,17 @@ class Model extends Object
$sql .= ', '; $sql .= ', ';
} }
$sql .= $column . ' = ?'; $sql .= $column . ' = ';
if (in_array($value, array('++', '--')))
{
$sql .= $column . ' ' . substr($value, 0, 1) . ' ?';
$value = 1;
}
else
{
$sql .= '?';
}
} }
else else
{ {