use MooseX::Declare;
class SQL::Translator::Object::Column {
- use MooseX::Types::Moose qw(Bool HashRef Int Maybe Str);
- use SQL::Translator::Types qw(Trigger);
+ use MooseX::Types::Moose qw(ArrayRef Bool HashRef Int Maybe Str);
+ use SQL::Translator::Types qw(ColumnSize Constraint Trigger);
extends 'SQL::Translator::Object';
has 'name' => (
has 'size' => (
is => 'rw',
- isa => Maybe[Int],
- required => 1
+ isa => ColumnSize,
+ coerce => 1,
+ auto_deref => 1,
);
has 'is_nullable' => (
isa => Bool,
default => 0
);
+
+ has 'is_foreign_key' => (
+ is => 'rw',
+ isa => Bool,
+ default => 0
+ );
+
+ has 'foreign_key_reference' => (
+ is => 'rw',
+ isa => Constraint,
+ );
has 'trigger' => (
is => 'rw',
isa => HashRef,
auto_deref => 1,
);
+
+ around size(@args) {
+ $self->$orig(@args) if @args;
+ my @sizes = $self->$orig;
+ return wantarray ? @sizes
+ : join ',', @sizes;
+ }
}
use MooseX::Declare;
class SQL::Translator::Object::ForeignKey {
- use SQL::Translator::Types qw(Index PrimaryKey);
+ use MooseX::Types::Moose qw(ArrayRef Maybe Undef Str);
extends 'SQL::Translator::Object::Constraint';
has '+type' => (
- default => 'FOREIGN_KEY',
+ default => 'FOREIGN KEY',
);
- has 'references' => (
- isa => PrimaryKey | Index,
+ has 'reference_columns' => (
+ isa => ArrayRef | Undef,
+ is => 'rw',
+ auto_deref => 1
+ );
+
+ has 'on_delete' => (
+ isa => Maybe[Str],
+ is => 'rw',
+ );
+
+ has 'on_update' => (
+ isa => Maybe[Str],
+ is => 'rw',
+ );
+
+ has 'reference_table' => (
+ isa => Str,
is => 'rw',
- required => 1,
);
+
+ method reference_fields { return $self->reference_columns }
}
);
method get_fields { return $self->get_columns }
+ method primary_key(Str $column) {
+ $self->get_column($column)->is_primary_key(1);
+ }
}