开发者

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/my开发者_开发技巧app_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?


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.


I make so and it worked:

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
    create=static components=TimeStamp dbi:SQLite:myapp.db \
    on_connect_do="PRAGMA foreign_keys = ON" \
    overwrite_modifications=1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜