[Dbix-class] Inflated DateTime column not updated on $row->update({ ts_column => undef })

Lasse Makholm lasse at unity3d.com
Fri May 22 19:57:35 GMT 2015


It seems DBIx::Class::InflateColumn::DateTime does not update the inflated
column value on: $row->update({ ts_column => undef })

Given:

CREATE TABLE `foo` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `ts` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

Doing:

package My::Schema;

use DateTime;
use base qw(DBIx::Class::Schema::Loader);

__PACKAGE__->loader_options(
components => [qw(InflateColumn::DateTime)],
naming => "current",
);

package main;

my $schema = My::Schema->connect("dbi:mysql:test");
$schema->storage->debug(1);

print "create";
my $foo = $schema->resultset('Foo')->create({ ts => DateTime->now });
print "ts = ", defined($foo->ts) ? $foo->ts : 'null';

print "update({ ts => undef })";
$foo->update({ ts => undef });
print "ts = ", defined($foo->ts) ? $foo->ts : 'null';

print "discard_changes";
$foo->discard_changes;
print "ts = ", defined($foo->ts) ? $foo->ts : 'null';

Yields:

create
BEGIN WORK
INSERT INTO `foo` ( `ts`) VALUES ( ? ): '2015-05-22 19:44:54'
COMMIT
ts = 2015-05-22T19:44:54

update({ ts => undef })
UPDATE `foo` SET `ts` = ? WHERE ( `id` = ? ): NULL, '16'
ts = 2015-05-22T19:44:54

discard_changes
SELECT `me`.`id`, `me`.`ts` FROM `foo` `me` WHERE ( `me`.`id` = ? ): '16'
ts = null

I would have expected the inflated column value to be updated on update({
... }).

Passing a DateTime object instead of undef does update the inflated column
value appropriately.
And doing:

$row->ts_column(undef);
$row->update();

...(obviously) works as expected too.

Is this a known bug or by design? Or am I simply missing something?

Thanx
/L
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150522/0f3f6329/attachment.htm>


More information about the DBIx-Class mailing list