DBIC::Schema::Loaderã®ã«ã¹ã¿ãã¤ãºã¨è¨ããã¿ã§ãã¬ã¼ã³ããã¯ãã ã£ã件
話ãã¦ãªããã©ãè³æã¯ããã®ã§å ¬éãã¾ã£ããã
æ¦è¦
éçºä¸ã«ã¹ãã¼ãã«å¤æ´ãçºçãã¦ãmake_schema_at()ãä½åº¦ãå©ãéã«å°ããã¨ã¨ãSchema::Loaderã§æ¯è¼çæå³ããéãã«Schema, Tableã¯ã©ã¹ãçæããçºã«ããããªé¢¨ã«ããã¨ãããã£ã¦å 容ã§ãã
ãã£ãã¡ãªäººåã
ãããªæãã
å
容ã®è§£èª¬ã¯ãã¬ã¼ã³è³æãè¦ã¦ãã ããã
#!/usr/bin/perl use strict; use warnings; use FindBin; use File::Spec; use lib ( File::Spec->catfile( $FindBin::Bin, qw/.. lib/ ), File::Spec->catfile( $FindBin::Bin, qw/.. schema/ ) ); use DBIx::Class::Schema::Loader qw(make_schema_at); die unless @ARGV; my $schema_class = 'MyClass::DBIC::Schema'; unlink( glob( File::Spec->catdir( $FindBin::Bin, '..', 'lib', split( /::/, $schema_class ) ) . '/*.pm' ) ); use DBIx::Class::Schema::Loader::Base; package DBIx::Class::Schema::Loader::Base; use String::CamelCase qw(decamelize); { no warnings 'redefine'; sub _load_relationships { my ( $self, $table ) = @_; my $tbl_fk_info = $self->_table_fk_info($table); foreach my $fkdef (@$tbl_fk_info) { $fkdef->{remote_source} = $self->monikers->{ delete $fkdef->{remote_table} }; } my $local_moniker = $self->monikers->{$table}; my $rel_stmts = $self->{relbuilder} ->generate_code( $local_moniker, $tbl_fk_info ); foreach my $src_class ( sort keys %$rel_stmts ) { my $src_stmts = $rel_stmts->{$src_class}; foreach my $stmt (@$src_stmts) { if ($stmt->{method} eq 'belongs_to') { my $table_class_suffix = [split /::/ => $stmt->{args}->[1]]->[-1]; $stmt->{args}->[0] = decamelize($table_class_suffix); } $self->_dbic_stmt( $src_class, $stmt->{method}, @{ $stmt->{args} } ); } } } } package main; make_schema_at( $schema_class, { components => [ qw/ResultSetManager UTF8Columns InflateColumn::DateTime TimeStamp / ], dump_directory => File::Spec->catfile( $FindBin::Bin, qw/.. lib/ ), debug => 0, really_erase_my_files => 0, exclude => qr/Base$/, }, \@ARGV, );
ã¾ãã俺æ§Loaderä½ããªããã¯DBICã使ããªãã®ããã¹ããã©ã¯ãã£ã¹ãªæ°ããã¾ãã(åè«ã ãã©)
SEE ALSO
- http://d.hatena.ne.jp/woremacx/20080309/1205031715 å¾ã§è©¦ã