Subject: | add/remove_column |
hi
i am using DBIx:Class 0.08118 under my gentoo server.
i found i little problem with
DBIx:Class:ResultSource add_column method when i use it afre
remove_collumn method
Show quoted text
>perl -v
This is perl, v5.8.8 built for x86_64-linux
Show quoted text>eix DBIx
[I] dev-perl/DBIx-Class
Available versions: (~)0.08115 (~)0.08117 (~)0.08118 {test}
Installed versions: 0.08118(11:56:11 AM 03/22/2010)(-test)
Show quoted text>uname -a
Linux garmond 2.6.30-gentoo-r5 #1 SMP Tue Oct 6 17:53:37 CEST 2009
x86_64 Intel(R) Xeon(R) CPU X3220 @ 2.40GHz GenuineIntel GNU/Linux
explanation:
i am using DBIx::Class::Schema::Loader for automated dumping of DB
tables to schema.
this Loader provides md5sum of generated data, and check it after each
run, so i wont modify generated part.
instead of modify generated code, i can add own code, and it will be
preserved.
because Loader only list columns in generated file(s),
i want to add own accessor name to one column.
so i did this:
__PACKAGE__->remove_column('colname'); # to remove already added column
from Loader
__PACKAGE__->add_columns( "colname", { accessor => '_colname' } ); # to
add same column but with defined accessor
and write own sub colname {} to handle this column.
but instead of calling my method, DBIx calls directly colname, so i
cannot modify return value as i planned to do.
if i try to add accesor directly in first call it works as expected.
to reproduce do this:
1. create some schema
2. add lines
__PACKAGE__->remove_column('colname') to remove already added column
__PACKAGE__->add_columns( "colname", { accessor => '_colname' } ) to add
same column but with defined accessor
sub colname {
my $self = shift;
return 'from accessor: '.$self->_colname;
}
3. call schema and get colname value to see return value (it wont
contains 'from accessor' string