[prev] [thread] [next] [Date index for 2004/12/20]
Hello,
I've found what I consider a bug in the attribute system. I first ran
across this problem last week when working on a table with mixed case
column names and using the _attribute_set() method. Attached is a test
case to reproduce the problem. Essentially it boils down to attributes
being all lower case within the object. So if you have a column "Foo"
and you call $self->_attribute_set("Foo", "bar") it will not get
saved. But if you use an all lowercase column name it works fine. I
definitely expected to be able to use the proper case on these
methods, which is why it took me so long to figure it out.
So at a minimum the requirement to use lower base column names needs
to be documented. I would also be happy to work out a patch that would
also allow the use of the proper cased name if Tony would accept it.
I'm mostly there, but haven't found all the corners yet.
Drew
package Recipe;
use strict;
use warnings;
use base 'Class::DBI';
__PACKAGE__->connection('dbi:mysql:database=recipes;host=localhost',
'recipe', 'recipe');
__PACKAGE__->add_trigger('before_create', \&_beforeCreate);
__PACKAGE__->add_trigger('before_update', \&_beforeUpdate);
__PACKAGE__->table('Recipe');
__PACKAGE__->columns(Primary => 'Id');
__PACKAGE__->columns(Essential=>qw(Intro Created CreatedBy Modified
ModifiedBy));
#==========================================================================
sub now {
my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
$mon += 1; $year += 1900;
return sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $mon, $mday,
$hour, $min, $sec);
}
#==========================================================================
sub _beforeCreate {
my $self = shift;
$self->_attribute_set(Created=>now());
$self->_attribute_set(CreatedBy=>$ENV{USER});
}
#==========================================================================
sub _beforeUpdate {
my $self = shift;
$self->_attribute_set(Modified=>now());
$self->_attribute_set(ModifiedBy=>$ENV{USER});
}
1;
--
----------------------------------------------------------------
Drew Taylor * Web development & consulting
Email: drew@xxxxxxxxxx.xxx * Site implementation & hosting
Web : www.drewtaylor.com * perl/mod_perl/DBI/mysql/postgres
----------------------------------------------------------------
|
Problem with _attribute_* methods
|
|
Re: Problem with _attribute_* methods
|
Generated at 08:50 on 21 Dec 2004 by mariachi v0.52