From: Justin Hunter Date: Tue, 21 Jun 2011 18:25:28 +0000 (-0700) Subject: add an around BUILDARGS to process fields arg properly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d971846de97d9dc04e6f112600f1e25c699a608c;p=dbsrgits%2FSQL-Translator-2.0-ish.git add an around BUILDARGS to process fields arg properly --- diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index b16f395..91dbff0 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -104,4 +104,17 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object { } method is_valid { return $self->has_type && scalar $self->column_ids ? 1 : undef } + + around BUILDARGS(ClassName $self: @args) { + my $args = $self->$orig(@args); + + my $fields = delete $args->{fields} || []; + + $fields = ref($fields) eq 'ARRAY' ? $fields : [ $fields ]; + my $ix_hash = Tie::IxHash->new(); + $ix_hash->STORE($_, SQL::Translator::Object::Column->new( name => $_ )) for @$fields; + $args->{columns} = $ix_hash; + + return $args; + } }