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);
+ }
}