]> Dogcows Code - chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate/commitdiff
Add unique constraints on columns referenced by foreign keys
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Mon, 22 Aug 2011 10:18:10 +0000 (11:18 +0100)
committerDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Mon, 22 Aug 2011 10:18:10 +0000 (11:18 +0100)
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

index aedd4354af028c112d81492a15ae728ccd7a22ac..b355e52655c7feaf723d85d34e4a8fc94b09428a 100644 (file)
@@ -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' });
This page took 0.021394 seconds and 4 git commands to generate.