Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent DBIx::Class::Schema::Loader from automatically adding InflateColumn::DateTime in Catalyst?

I am using Catalyst and DBIx::Class::Schema::Loader to create my model in Catalyst like so:

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static overwrite_modifications=1 components=EncodedColumn dbi:mysql:mydb mydb pass

Unfortunately the loader automatically sets up InflateColumn::DateTime as a default component, which I do not want. I want the raw value from the database.

__PACKAGE__->load_components("InflateColumn::DateTime", "EncodedColumn");

Can anyone tell me how to prevent this?

like image 308
Rob Boerman Avatar asked Jan 31 '11 11:01

Rob Boerman


1 Answers

Man, that is annoying. Looks like it's not possible to get what you want as it is.

_build_loader_components in Catalyst::Helper::Model::DBIC::Schema adds it unless you have no namespaces and no resultset namespace. It pushes your extra component= list onto that.

my @components = $self->old_schema && (not $use_namespaces) ? ()
    : ('InflateColumn::DateTime');                                 

So, options–

  1. File a bug.
  2. Do it with dbicdump.

This should be what you wanted–

dbicdump -o dump_directory=./lib \
    -o components='["EncodedColumn"]' \
    -o use_namespaces=1 \
    -o overwrite_modifications=1 \
    MyApp::Schema dbi:mysql:foo user pass

And then just the plain model to wrap it–

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema

Update: Took out preserve_case as your example didn’t use it and I’d like to mention for the sake of best practices that the password should not be in the model or the schema classes. It should be in config and if you’re using something that allows it, like mysql, it should be configured to be read from a privilege restricted DB specific configuration file.

like image 116
Ashley Avatar answered Sep 18 '22 01:09

Ashley