Dynamic updates appear to work, but only correctly once. I'm wondering why and welcome suggestions for an optimal fix.
To illustrate, consider a model that uses dynamic updates with schema:
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| strcol1 | varchar(255) | YES | | NULL | |
| intcol2 | int(11) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
initial model creation works fine with query:
INSERT INTO
test(
strcol1,
intcol2) VALUES (DEFAULT, DEFAULT)
However, the following code on an instance of a new Test
model:
$test->strcol1 = 'foo';
$test->save();
$test->intcol2 = 123;
$test->save();
gives SQL:
UPDATE `test` SET `strcol1` = 'foo' WHERE `id` = '4'
UPDATE `test` SET `strcol1` = 'foo', `intcol2` = 123 WHERE `id` = '4'
Why would strcol1
be set again when it has not changed since the first save? While not especially an issue in this case, were the value for a column set as rawvalue now()
for example, it could produce unintended results.
This is with 2.0.10. Any suggested workaround/fix at this point?