[Dbix-class] Problem with using InflateColumn::DateTime
Matt S Trout
dbix-class at trout.me.uk
Sat Sep 30 18:20:06 CEST 2006
J Cook wrote:
> Hi,
>
> I'm trying to reformat a date field from a MySQL table - wanting to go
> from yyyy-mm-dd to mm/dd/yyyy when displayed on a webpage. So, following
> some advice I did the following:
>
> package DB::Main::Book;
>
> use base qw/DBIx::Class/;
>
> # Load required DBIC stuff
> __PACKAGE__->load_components(qw/PK::Auto Core InflateColumn::DateTime/);
> # Set the table name
> __PACKAGE__->table('books');
> # Set columns in table
> __PACKAGE__->add_columns(date => { data_type => 'date' });
> __PACKAGE__->add_columns(qw/id book author date/);
> # # Set the primary key for the table
> __PACKAGE__->set_primary_key('id');
>
> Next in my code(Mason page):
> <% $quote->depart_date->mdy() %> depart date<br>
>
> I get the following result:
>
> Can't call method "mdy" without a package or object reference at
>
>
> It works fine without the '->mdy()' but of course doesn't format the
> date as wished for.
>
> I followed the doc and I've tried several variations but this looks like
> it should work according to how the doc looks.
>
> Any suggestions?
__PACKAGE__->load_components(qw/PK::Auto Core InflateColumn::DateTime/);
should be
__PACKAGE__->load_components(qw/InflateColumn::DateTime Core/);
PK::Auto is in Core as of 0.07, but left-most loaded component is most
significant so without putting InflateColumn::DateTime to the left of Core its
overrides won't be seen.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list