fixing bugs on sf turnkey tracker
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / ClassDBI.pm
index 1b7d900..ec72fce 100755 (executable)
@@ -1,7 +1,7 @@
 package SQL::Translator::Producer::ClassDBI;
 
 # -------------------------------------------------------------------
-# $Id: ClassDBI.pm,v 1.35 2003-08-20 15:55:00 kycl4rk Exp $
+# $Id: ClassDBI.pm,v 1.39 2003-12-04 18:48:33 kycl4rk Exp $
 # -------------------------------------------------------------------
 # Copyright (C) 2003 Allen Day <allenday@ucla.edu>,
 #                    Ying Zhang <zyolive@yahoo.com>
@@ -23,7 +23,7 @@ package SQL::Translator::Producer::ClassDBI;
 
 use strict;
 use vars qw[ $VERSION $DEBUG ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.35 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.39 $ =~ /(\d+)\.(\d+)/;
 $DEBUG = 1 unless defined $DEBUG;
 
 use SQL::Translator::Schema::Constants;
@@ -275,12 +275,6 @@ sub produce {
                   . "sub $fk_method {\n"
                   . "    return shift->$field_name\n}\n\n";
 
-                #
-                # If this table "has a" to the other, then it follows 
-                # that the other table "has many" of this one, right?
-                #
-                # No... there is the possibility of 1-1 cardinality
-                #
                 # if there weren't M-M relationships via the has_many
                 # being set up here, create nice pluralized method alias
                 # rather for user as alt. to ugly tablename_fieldname name
@@ -321,7 +315,8 @@ sub produce {
         sort { $packages{ $a }{'order'} <=> $packages{ $b }{'order'} }
         keys %packages
     ) {
-        my $pkg = $packages{$pkg_name};
+        my $pkg = $packages{$pkg_name} or next;
+        next unless $pkg->{'pkg_name'};
 
         $create .= join ( "\n",
             $sep,
@@ -330,60 +325,20 @@ sub produce {
             "use Class::DBI::Pager;\n\n",
         );
 
-        #        if ( $from ) {
-        #            $create .= 
-        #                $pkg->{'pkg_name'}."->set_up_table('".$pkg->{'table'}."');\n\n";
-        #        }
-        #        else {
-        #            my $table       = $schema->get_table( $pkg->{'table'} );
-        #            my @field_names = map { $_->name } $table->get_fields;
-        #
-        #            $create .= join("\n",
-        #                $pkg_name."->table('".$pkg->{'table'}."');\n",
-        #                $pkg_name."->columns(All => qw/".
-        #                join(' ', @field_names)."/);\n\n",
-        #            );
-        #        }
-
-        #
-        # The approach here is to do lazy loading on the expensive
-        # columns (expensive defined as those columns which require
-        # construction of a referenced object) fields which are
-        # strictly data (ie, not references) are treated as essential
-        # b/c they don't require much time to set up.
-        #
-        $create .= $pkg_name . "->table('" . $pkg->{'table'} . "');\n";
-
-        #
-        # Set up primary key field.
-        #
-        if ( $pkg->{'_columns_primary'} ) {
-            $create .= $pkg_name
-              . "->columns(Primary   => qw/"
-              . $pkg->{'_columns_primary'} . "/);\n";
-        }
-        else {
-            die "Class::DBI isn't going to like that you don't " .
-              "have a primary key field for table " . $pkg->{'table'};
-        }
-
-        #
-        # Set up non-FK fields to be populated at construction.
-        #
-        if ( $pkg->{'_columns_essential'} ) {
-            $create .= $pkg_name
-              . "->columns(Essential => qw/"
-              . join ( ' ', @{ $pkg->{'_columns_essential'} } ) . "/);\n";
-        }
-
-        #
-        # Set up FK fields for lazy loading on request.
-        #
-        if ( $pkg->{'_columns_others'} ) {
-            $create .= $pkg_name
-              . "->columns(Others    => qw/"
-              . join ( ' ', @{ $pkg->{'_columns_others'} } ) . "/);\n";
-        }
+                if ( $from ) {
+                    $create .= 
+                        $pkg->{'pkg_name'}."->set_up_table('".$pkg->{'table'}."');\n\n";
+                }
+                else {
+                    my $table       = $schema->get_table( $pkg->{'table'} );
+                    my @field_names = map { $_->name } $table->get_fields;
+                                       
+                    $create .= join("\n",
+                        $pkg_name."->table('".$pkg->{'table'}."');\n",
+                        $pkg_name."->columns(All => qw/".
+                        join(' ', @field_names)."/);\n\n",
+                    );
+                }
 
         $create .= "\n";
 
@@ -430,6 +385,6 @@ configuration.  See L<Class::DBI> for details on how this works.
 
 =head1 AUTHORS
 
-Allen Day E<lt>allenday@ucla.eduE<gt>
+Allen Day E<lt>allenday@ucla.eduE<gt>,
 Ying Zhang E<lt>zyolive@yahoo.comE<gt>,
 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.