App-mkfeyorm
view release on metacpan or search on metacpan
lib/App/mkfeyorm.pm view on Meta::CPAN
[% END -%]
for my $relation ( @{ $params{fk_relations} } ) {
my $source_table = $relation->{source_table};
my $source_column = $relation->{source_column};
my $target_table = $relation->{target_table};
my $target_column = $relation->{target_column};
my $fk = Fey::FK->new(
source_columns => $schema->table($source_table)->column($source_column),
target_columns => $schema->table($target_table)->column($target_column),
);
$schema->add_foreign_key($fk);
}
}
#
# Add foreign key if it is needed or remove it
#
#my $fk;
#
#$fk = Fey::FK->new(
# source_columns => $schema->table('src_table')->column('col_id'),
# target_columns => $schema->table('dest_table')->column('col_id'),
#);
#$schema->add_foreign_key($fk);
[% IF CACHE -%]
if ($params{cache_file}) {
if (!-e $params{cache_file} || $updated) {
my $dirname = dirname($params{cache_file});
make_path($dirname) unless -e $dirname;
store($schema, $params{cache_file});
}
}
[% END -%]
has_schema $schema;
__PACKAGE__->DBIManager->add_source($source);
return 1;
}
sub _load_tables {
my @tables = @_;
$_->load for @tables;
return 1;
}
1;
__[ table.tt ]__
package [% TABLE %];
use Fey::ORM::Table;
use [% SCHEMA %];
use Moose;
use MooseX::SemiAffordanceAccessor;
use MooseX::StrictConstructor;
use namespace::autoclean;
sub load {
my $class = shift;
return unless $class;
return if $class->Table;
my $schema = [% SCHEMA %]->Schema;
my $table = $schema->table('[% DB_TABLE %]');
has_table( $table );
#
# Add another relationships like has_one, has_many or etc.
#
#has_many items => ( table => $schema->table('item') );
}
1;
( run in 1.357 second using v1.01-cache-2.11-cpan-99c4e6809bf )