From: Jess Robinson Date: Sun, 22 Jan 2006 21:23:51 +0000 (+0000) Subject: Working version.. X-Git-Tag: v0.05005~117^2~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dc441df3fcb5dbda2365ebfd2d5f36a4ea84372;p=dbsrgits%2FDBIx-Class.git Working version.. --- diff --git a/lib/SQL/Translator/Producer/DBIx/Class/File.pm b/lib/SQL/Translator/Producer/DBIx/Class/File.pm index 736bd73..cfc8d92 100644 --- a/lib/SQL/Translator/Producer/DBIx/Class/File.pm +++ b/lib/SQL/Translator/Producer/DBIx/Class/File.pm @@ -57,8 +57,11 @@ sub produce $tt_vars{pkclass} = $pkclass; my $schemaoutput .= << "DATA"; + package ${dbixschema}; use base 'DBIx::Class::Schema'; +use strict; +use warnings; DATA my %tableoutput = (); @@ -67,8 +70,11 @@ DATA { my $tname = $table->name; my $output .= qq{ + package ${dbixschema}::${tname}; use base 'DBIx::Class'; +use strict; +use warnings; __PACKAGE__->load_components(qw/${pkclass} Core/); __PACKAGE__->table('${tname}'); @@ -106,7 +112,7 @@ __PACKAGE__->table('${tname}'); { my @pk = map { $_->name } ($pk->fields); $output .= "__PACKAGE__->set_primary_key("; - $output .= "'" . join("', '", @pk) . "');"; + $output .= "'" . join("', '", @pk) . "');\n"; } foreach my $cont ($table->get_constraints) @@ -114,7 +120,11 @@ __PACKAGE__->table('${tname}'); # print Data::Dumper::Dumper($cont->type); if($cont->type =~ /foreign key/i) { - $output .= "\n__PACKAGE__->belongs_to('" . +# $output .= "\n__PACKAGE__->belongs_to('" . +# $cont->fields->[0]->name . "', '" . +# "${dbixschema}::" . $cont->reference_table . "');\n"; + + $tableextras{$table->name} .= "\n__PACKAGE__->belongs_to('" . $cont->fields->[0]->name . "', '" . "${dbixschema}::" . $cont->reference_table . "');\n"; @@ -126,23 +136,22 @@ __PACKAGE__->table('${tname}'); } } - $tableoutput{$table->name} = $output; + $tableoutput{$table->name} .= $output; } - foreach my $te (keys %tableextras) + foreach my $to (keys %tableoutput) { - $tableoutput{$te} .= $tableextras{$te} . "\n"; + $output .= $tableoutput{$to}; + $schemaoutput .= "\n__PACKAGE__->register_class('${to}', '${dbixschema}::${to}');\n"; } - $schemaoutput .= "\n__PACKAGE__->load_classes("; - foreach my $to (keys %tableoutput) + foreach my $te (keys %tableextras) { - $output .= $tableoutput{$to}; - $schemaoutput .= "'${to}',"; + $output .= "\npackage ${dbixschema}::$te;\n"; + $output .= $tableextras{$te} . "\n"; +# $tableoutput{$te} .= $tableextras{$te} . "\n"; } - chop $schemaoutput; - $schemaoutput .= ");\n"; # print "$output\n"; - return $schemaoutput . $output . "\n1;\n"; + return "${output}\n\n${schemaoutput}\n1;\n"; }