Skip to content

Commit

Permalink
Schema/Field: add foreign_key_reference builder
Browse files Browse the repository at this point in the history
foreign_key_reference was only being set from the is_foreign_key
builder.  If a user manually set is_foreign_key, as DBIx::Class does,
foreign_key_reference would never be set, breaking the HTML producer.
  • Loading branch information
andrewgregory committed Jun 27, 2015
1 parent 9aabed4 commit 35554bc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/SQL/Translator/Schema/Field.pm
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ has foreign_key_reference => (
is => 'rw',
predicate => '_has_foreign_key_reference',
isa => schema_obj('Constraint'),
builder => 1,
weak_ref => 1,
);

Expand All @@ -197,6 +198,22 @@ around foreign_key_reference => sub {
$self->$orig;
};

sub _build_foreign_key_reference {
my ( $self ) = @_;

if ( my $table = $self->table ) {
for my $c ( $table->get_constraints ) {
if ( $c->type eq FOREIGN_KEY ) {
my %fields = map { $_, 1 } $c->fields;
if ( $fields{ $self->name } ) {
return $c;
}
}
}
}
return undef;
}

=head2 is_auto_increment
Get or set the field's C<is_auto_increment> attribute.
Expand Down

0 comments on commit 35554bc

Please sign in to comment.