From 45d3acef815c1fb052b317bc81bb7470a34cde30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 22 Aug 2011 11:18:10 +0100 Subject: [PATCH] Add unique constraints on columns referenced by foreign keys PostgreSQL correctly throws an error if you try to create a foreign key and there isn't a unique constraint on the referenced columns, since it could end up referencing multiple rows. --- t/lib/DBSchema/Result/Dvd.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/lib/DBSchema/Result/Dvd.pm b/t/lib/DBSchema/Result/Dvd.pm index aedd435..b355e52 100644 --- a/t/lib/DBSchema/Result/Dvd.pm +++ b/t/lib/DBSchema/Result/Dvd.pm @@ -45,6 +45,8 @@ __PACKAGE__->add_columns( }, ); __PACKAGE__->set_primary_key('dvd_id'); +__PACKAGE__->add_unique_constraint(dvd_name => [qw(name)]); +__PACKAGE__->add_unique_constraint(dvd_twokeys => [qw(twokeysfk)]); __PACKAGE__->belongs_to('owner', 'DBSchema::Result::User', 'owner'); __PACKAGE__->belongs_to('current_borrower', 'DBSchema::Result::User', 'current_borrower', { join_type => "LEFT" }); __PACKAGE__->has_many('dvdtags', 'Dvdtag', { 'foreign.dvd' => 'self.dvd_id' }); -- 2.45.2