From: Justin Hunter Date: Tue, 6 Oct 2009 23:27:24 +0000 (-0700) Subject: View extends Table X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3330f9a32502405e4b05c3c73f66d9f86452d8f;p=dbsrgits%2FSQL-Translator-2.0-ish.git View extends Table --- diff --git a/lib/SQL/Translator/Object/View.pm b/lib/SQL/Translator/Object/View.pm index e800cbb..f23e070 100644 --- a/lib/SQL/Translator/Object/View.pm +++ b/lib/SQL/Translator/Object/View.pm @@ -1,33 +1,16 @@ use MooseX::Declare; -class SQL::Translator::Object::View extends SQL::Translator::Object { +class SQL::Translator::Object::View extends SQL::Translator::Object::Table { use MooseX::Types::Moose qw(HashRef Str); - use SQL::Translator::Types qw(Column); - - has 'name' => ( - is => 'rw', - isa => Str, - required => 1 - ); - - has 'columns' => ( - traits => ['Hash'], - is => 'rw', - isa => HashRef[Column], - handles => { - exists_column => 'exists', - column_ids => 'keys', - get_columns => 'values', - get_column => 'get', - add_column => 'set', - }, - default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, - ); + use SQL::Translator::Types qw(Column Schema); has 'sql' => ( is => 'rw', isa => Str, - required => 1 ); - around add_column(Column $column) { $self->$orig($column->name, $column) } + around add_column(Column $column does coerce) { + die "Can't use column name " . $column->name if $self->exists_column($column->name) || $column->name eq ''; + $column->table($self); + return $self->$orig($column->name, $column); + } }