And then there were none.

This commit is contained in:
Joshua Sherman 2014-01-20 01:25:11 -05:00
parent 54cb6dfe83
commit 7c8ae14b75
2 changed files with 24 additions and 25 deletions

View file

@ -1103,6 +1103,10 @@ class Model extends Object
* where you could have a mixed lot that would attempt to
* build out a query with both INSERT and UPDATE syntax and
* would probably cause a doomsday scenario for our universe.
* @todo Doesn't play nice with ->walk() at all. Ends up stuck in
* an infinite loop and never executes. Could be part of the
* aforementioned doomsday scenario and fortunately PHP isn't
* letting it happen thanks to memory constraints.
*/
foreach ($this->records as $record)
{
@ -1151,17 +1155,11 @@ class Model extends Object
$sql .= '; ';
}
$sql .= 'UPDATE ' . $this->table . ' SET ' . implode(', ', $update_fields) . ' WHERE ';
$sql .= 'UPDATE ' . $this->table
. ' SET ' . implode(', ', $update_fields)
. ' WHERE ' . $this->columns['id'] . ' = ?';
if (isset($record[$this->columns['id']]))
{
$sql .= $this->columns['id'] . ' = ?';
$input_parameters[] = $record[$this->columns['id']];
}
else
{
throw new Exception('Missing UID field.');
}
$input_parameters[] = $record[$this->columns['id']];
}
// Performs a multiple row INSERT
else
@ -1224,7 +1222,7 @@ class Model extends Object
return $results;
}
// Single row INSERT or UPDATE
elseif (count($this->record) > 0)
else
{
// Determines if it's an UPDATE or INSERT
$update = (isset($this->record[$this->columns['id']]) && trim($this->record[$this->columns['id']]) != '');

View file

@ -603,20 +603,21 @@ class ModelTest extends PHPUnit_Framework_TestCase
$this->assertEquals($count + 5, $model->record['count']);
}
# public function testMultipleQueueUpdate()
# {
# $model = new MockModel(['conditions' => ['id <=' => 5]]);
#
# var_dump($model->records);
#
# # while ($model->walk())
# # {
# # $model->record['field1'] = String::random();
# # $model->queue();
# # }
#
# # $model->commit();
# }
public function testMultipleQueueUpdate()
{
$_SESSION['__pickles']['security']['user_id'] = 1;
$model = new MockModel();
for ($i = 3; $i <= 5; $i++)
{
$model->record['id'] = $i;
$model->record['field1'] = String::random();
$model->record['updated_id'] = 1;
$model->queue();
}
$model->commit();
}
}
?>