From: Justin Hunter Date: Mon, 26 Jul 2010 23:36:47 +0000 (-0700) Subject: fix issue with order being wrong X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=815822d5f3e5685d46adcbb7fbaf296f27006ee6;p=dbsrgits%2FSQL-Translator-2.0-ish.git fix issue with order being wrong --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index ced7ce0..80aea11 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -103,6 +103,11 @@ class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { isa => Trigger, ); + has '_order' => ( + is => 'rw', + isa => Int, + ); + around size(@args) { $self->$orig(@args) if @args; my @sizes = $self->$orig; @@ -113,9 +118,6 @@ class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { method full_name { $self->table->name . '.' . $self->name } method schema { $self->table->schema } - method order { } - method is_unique { } - before name($name?) { die "Can't use column name $name" if defined $name && $self->table->exists_column($name) && $name ne $self->name } multi method size(Str $size) { my ($length, $precision) = split /,/, $size; $self->length($length); $self->precision($precision) if $precision; $self->size } @@ -130,8 +132,19 @@ class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { : $self->length; } + multi method order(Int $order) { $self->_order($order); } + multi method order { + my $order = $self->_order; + unless (defined $order && $order) { + my $columns = Tie::IxHash->new( map { $_->name => $_ } $self->table->get_columns ); + $order = ($columns->Indices($self->name) + 1) || 0; + $self->_order($order); + } + return $order; + } + method BUILD(HashRef $args) { die "Cannot use column name $args->{name}" if $args->{name} eq ''; - $self->size($args->{size}) if $args->{size} + $self->size($args->{size}) if $args->{size}; } }