primary key fix
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Parser / DDL / MySQL.pm
index afeef11..e577f33 100644 (file)
@@ -70,7 +70,7 @@ role SQL::Translator::Parser::DDL::MySQL {
                 $field->comments($fdata->{comments});
                 $table->add_column($field);
     
-                $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
+                $field->is_primary_key(1) if $fdata->{is_primary_key};
 
                 my %extra;
                 for my $qual ( qw[ binary unsigned zerofill list collate ],
@@ -107,25 +107,25 @@ role SQL::Translator::Parser::DDL::MySQL {
             }
             
     
-#            if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
-#                my @cleaned_options;
-#                my @ignore_opts = $self->parser_args->{'ignore_opts'}
-#                    ? split( /,/, $self->parser_args->{'ignore_opts'} )
-#                    : ();
-#                if (@ignore_opts) {
-#                    my $ignores = { map { $_ => 1 } @ignore_opts };
-#                    foreach my $option (@options) {
-#                        # make sure the option isn't in ignore list
-#                        my ($option_key) = keys %$option;
-#                        if ( !exists $ignores->{$option_key} ) {
-#                            push @cleaned_options, $option;
-#                        }
-#                    }
-#                } else {
-#                    @cleaned_options = @options;
-#                }
-#                $table->options( \@cleaned_options ) or die $table->error;
-#            }
+            if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
+                my @cleaned_options;
+                my @ignore_opts = $translator->has_parser_args && $translator->parser_args->{'ignore_opts'}
+                    ? split( /,/, $translator->parser_args->{'ignore_opts'} )
+                    : ();
+                if (@ignore_opts) {
+                    my $ignores = { map { $_ => 1 } @ignore_opts };
+                    foreach my $option (@options) {
+                        # make sure the option isn't in ignore list
+                        my ($option_key) = keys %$option;
+                        if ( !exists $ignores->{$option_key} ) {
+                            push @cleaned_options, $option;
+                        }
+                    }
+                } else {
+                    @cleaned_options = @options;
+                }
+                $table->options( \@cleaned_options ); # or die $table->error;
+            }
     
             for my $cdata ( @{ $tdata->{constraints} || [] } ) {
                 my $constraint;
@@ -136,7 +136,7 @@ role SQL::Translator::Parser::DDL::MySQL {
                     $constraint = ForeignKey->new({ name => $cdata->{name} || '',
                                                     table => $table,
                                                     reference_table => $cdata->{reference_table},
-                                                    reference_columns => $cdata->{reference_fields},
+                                                    defined $cdata->{reference_fields} ? (reference_columns => $cdata->{reference_fields}) : (),
                                                     on_delete => $cdata->{on_delete} || $cdata->{on_delete_do},
                                                     on_update => $cdata->{on_update} || $cdata->{on_update_do} });
                     $table->get_column($_)->is_foreign_key(1) for @{$cdata->{fields}};