Skip to content

Commit

Permalink
Require fk when joining two tables
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Sep 25, 2011
1 parent 7d14829 commit f2af699
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/Fey/SQL/Fragment/Join.pm
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;
use namespace::autoclean;

use Fey::Exceptions qw( param_error );
use Fey::FakeDBI;
use Fey::Types qw( FK OuterJoinType Table WhereClause );
use List::AllUtils qw( pairwise );
Expand All @@ -25,9 +26,10 @@ has '_table2' => (
);

has '_fk' => (
is => 'ro',
isa => FK,
init_arg => 'fk',
is => 'ro',
isa => FK,
init_arg => 'fk',
predicate => '_has_fk',
);

has '_outer_type' => (
Expand All @@ -44,6 +46,15 @@ has '_where' => (
init_arg => 'where',
);

sub BUILD {
my $self = shift;

param_error 'You cannot join two tables with a foreign key'
if $self->_has_table2() && ! $self->_has_fk();

return;
}

sub id {
my $self = shift;

Expand Down

0 comments on commit f2af699

Please sign in to comment.