individual tables now returned as a hash of separate tt2 templates, keyed
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema / Table.pm
index 35f51f6..f18a798 100644 (file)
@@ -1,9 +1,9 @@
 package SQL::Translator::Schema::Table;
 
 # ----------------------------------------------------------------------
-# $Id: Table.pm,v 1.18 2003-08-29 14:54:01 kycl4rk Exp $
+# $Id: Table.pm,v 1.24 2004-02-09 22:15:15 kycl4rk Exp $
 # ----------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
+# Copyright (C) 2002-4 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -51,7 +51,7 @@ use Data::Dumper;
 use base 'Class::Base';
 use vars qw( $VERSION $FIELD_ORDER );
 
-$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.24 $ =~ /(\d+)\.(\d+)/;
 
 # ----------------------------------------------------------------------
 sub init {
@@ -135,25 +135,25 @@ C<SQL::Translator::Schema::Constraint> object.
     }
     #
     # See if another constraint of the same type 
-    # covers the same fields.
+    # covers the same fields.  -- This doesn't work!  ky
     #
-    elsif ( $constraint->type ne CHECK_C ) {
-        my @field_names = $constraint->fields;
-        for my $c ( 
-            grep { $_->type eq $constraint->type } 
-            $self->get_constraints 
-        ) {
-            my %fields = map { $_, 1 } $c->fields;
-            for my $field_name ( @field_names ) {
-                if ( $fields{ $field_name } ) {
-                    $constraint = $c;
-                    $ok = 0; 
-                    last;
-                }
-            }
-            last unless $ok;
-        }
-    }
+#    elsif ( $constraint->type ne CHECK_C ) {
+#        my @field_names = $constraint->fields;
+#        for my $c ( 
+#            grep { $_->type eq $constraint->type } 
+#            $self->get_constraints 
+#        ) {
+#            my %fields = map { $_, 1 } $c->fields;
+#            for my $field_name ( @field_names ) {
+#                if ( $fields{ $field_name } ) {
+#                    $constraint = $c;
+#                    $ok = 0; 
+#                    last;
+#                }
+#            }
+#            last unless $ok;
+#        }
+#    }
 
     if ( $ok ) {
         push @{ $self->{'constraints'} }, $constraint;
@@ -420,6 +420,38 @@ Determine whether the view is valid or not.
 }
 
 # ----------------------------------------------------------------------
+sub is_trivial_link {
+
+=pod
+
+=head2 is_data
+
+=cut
+
+    my $self = shift;
+    return 0 if $self->is_data;
+    return $self->{'is_trivial_link'} if defined $self->{'is_trivial_link'};
+
+    $self->{'is_trivial_link'} = 1;
+
+    my %fk = ();
+
+    foreach my $field ( $self->get_fields ) {
+         next unless $field->is_foreign_key;
+         $fk{$field->foreign_key_reference->reference_table}++;
+       }
+
+    foreach my $referenced (keys %fk){
+       if($fk{$referenced} > 1){
+         $self->{'is_trivial_link'} = 0;
+         last;
+       }
+    }
+
+    return $self->{'is_trivial_link'};
+
+}
+
 sub is_data {
 
 =pod