change "fields" into "columns" (backcompat), probably needs some error/type checking
Justin Hunter [Wed, 10 Feb 2010 23:31:07 +0000 (15:31 -0800)]
lib/SQL/Translator/Object/Table.pm

index ed27e27..13f83a7 100644 (file)
@@ -3,6 +3,7 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty {
     use MooseX::Types::Moose qw(Any Bool HashRef Str);
     use MooseX::MultiMethods;
     use SQL::Translator::Types qw(Column Constraint Index Schema Sequence);
+    use SQL::Translator::Object::Column;
     use SQL::Translator::Object::Constraint;
     clean;
 
@@ -167,4 +168,15 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty {
         die "Can't drop non-existant constraint " . $name unless $self->exists_constraint($name);
         $self->$orig($name);
     }
+
+    around BUILDARGS(ClassName $self: @args) {
+        my $args = $self->$orig(@args);
+
+        my $fields = delete $args->{fields};
+
+        tie %{$args->{columns}}, 'Tie::IxHash';
+        $args->{columns}{$_} = SQL::Translator::Object::Column->new( name => $_ ) for @$fields;
+
+        return $args;
+    }
 }