Permalink
Browse files

Require fk when joining two tables

  • Loading branch information...
1 parent 7d14829 commit f2af6991830d57c5d4e59ffd7a7086de43845e4d @autarch autarch committed Sep 25, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 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;

0 comments on commit f2af699

Please sign in to comment.