From: Dagfinn Ilmari Mannsåker Date: Mon, 22 Aug 2011 10:18:10 +0000 (+0100) Subject: Add unique constraints on columns referenced by foreign keys X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=45d3acef815c1fb052b317bc81bb7470a34cde30;p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate 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. --- 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' });