From: Justin Hunter Date: Wed, 30 Sep 2009 19:13:31 +0000 (-0700) Subject: set table/schema when added to table/schema, rather then on object construction X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e1bef8b98b4dfe178d9ce562f4b011644ab56a84;p=dbsrgits%2FSQL-Translator-2.0-ish.git set table/schema when added to table/schema, rather then on object construction --- diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 91e8cee..e79acf5 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -6,7 +6,6 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object { has 'table' => ( is => 'rw', isa => Table, - required => 1, weak_ref => 1, ); diff --git a/lib/SQL/Translator/Object/Index.pm b/lib/SQL/Translator/Object/Index.pm index 41ff945..2841caf 100644 --- a/lib/SQL/Translator/Object/Index.pm +++ b/lib/SQL/Translator/Object/Index.pm @@ -7,7 +7,6 @@ class SQL::Translator::Object::Index extends SQL::Translator::Object { has 'table' => ( is => 'rw', isa => Table, - required => 1, weak_ref => 1, ); diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index f1db51b..8fee3c7 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -75,8 +75,10 @@ class SQL::Translator::Object::Schema extends SQL::Translator::Object { around add_table(Table $table) { die "Can't use table name " . $table->name if $self->exists_table($table->name) || $table->name eq ''; + $table->schema($self); $self->$orig($table->name, $table); } + around add_view(View $view) { $self->$orig($view->name, $view) } around add_procedure(Procedure $procedure) { $self->$orig($procedure->name, $procedure) } around add_trigger(Trigger $trigger) { $self->$orig($trigger->name, $trigger) } diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 08388a5..46a4219 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -83,7 +83,6 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { is => 'rw', isa => Schema, weak_ref => 1, - required => 1, ); has 'temporary' => ( @@ -96,8 +95,10 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { 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); } + around add_constraint(Constraint $constraint) { my $name = $constraint->name; if ($name eq '') { @@ -105,8 +106,10 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { while ($self->exists_constraint('ANON' . $idx)) { $idx++ } $name = 'ANON' . $idx; } + $constraint->table($self); $self->$orig($name, $constraint) } + around add_index(Index $index does coerce) { my $name = $index->name; if ($name eq '') { @@ -114,8 +117,10 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { while ($self->exists_index('ANON' . $idx)) { $idx++ } $name = 'ANON' . $idx; } + $index->table($self); $self->$orig($name, $index) } + around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) } multi method primary_key(Any $) { grep /^PRIMARY KEY$/, $_->type for $self->get_constraints }