diff --git a/lib/Fey/SQL/Fragment/Join.pm b/lib/Fey/SQL/Fragment/Join.pm index 41c1342..4ca4425 100644 --- a/lib/Fey/SQL/Fragment/Join.pm +++ b/lib/Fey/SQL/Fragment/Join.pm @@ -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 ); @@ -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' => ( @@ -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;