More test schema relations for future tests
Peter Rabbitson [Fri, 24 Oct 2008 13:23:33 +0000 (13:23 +0000)]
t/lib/DBICTest/Schema/CD.pm
t/lib/DBICTest/Schema/CD_to_Producer.pm
t/lib/DBICTest/Schema/Genre.pm
t/lib/DBICTest/Schema/Producer.pm
t/lib/sqlite.sql

index 76b0372..d121027 100644 (file)
@@ -53,7 +53,10 @@ __PACKAGE__->many_to_many(
     { order_by => 'producer.name' },
 );
 
-__PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', { 'foreign.genreid' => 'self.genreid' });
+__PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre',
+    { 'foreign.genreid' => 'self.genreid' },
+    { join_type => 'left' },
+);
 
 #__PACKAGE__->add_relationship('genre', 'DBICTest::Schema::Genre',
 #    { 'foreign.genreid' => 'self.genreid' },
index 117a590..cf18c4e 100644 (file)
@@ -17,7 +17,8 @@ __PACKAGE__->belongs_to(
 
 __PACKAGE__->belongs_to(
   'producer', 'DBICTest::Schema::Producer',
-  { 'foreign.producerid' => 'self.producer' }
+  { 'foreign.producerid' => 'self.producer' },
+  { on_delete => undef, on_update => undef },
 );
 
 1;
index e72cd93..db2ca9c 100644 (file)
@@ -5,18 +5,19 @@ use strict;
 use base 'DBIx::Class::Core';
 
 __PACKAGE__->table('genre');
-__PACKAGE__->add_columns(qw/genreid name/);
+__PACKAGE__->add_columns(
+    genreid => {
+      data_type => 'integer',
+      is_auto_increment => 1,
+    },
+    name => {
+      data_type => 'varchar',
+      size => 100,
+    },
+);
 __PACKAGE__->set_primary_key('genreid');
+__PACKAGE__->add_unique_constraint ( genre_name => [qw/name/] );
 
-1;
-package DBICTest::Schema::Genre;
-
-use strict;
-
-use base 'DBIx::Class::Core';
-
-__PACKAGE__->table('genre');
-__PACKAGE__->add_columns(qw/genreid name/);
-__PACKAGE__->set_primary_key('genreid');
+__PACKAGE__->has_many (cds => 'DBICTest::Schema::CD', 'genreid');
 
 1;
index 036f9f2..26e140e 100644 (file)
@@ -17,4 +17,8 @@ __PACKAGE__->add_columns(
 __PACKAGE__->set_primary_key('producerid');
 __PACKAGE__->add_unique_constraint(prod_name => [ qw/name/ ]);
 
+__PACKAGE__->has_many(
+    producer_to_cd => 'DBICTest::Schema::CD_to_Producer' => 'producer'
+);
+
 1;
index 15967b3..d0e0bfd 100644 (file)
@@ -1,6 +1,6 @@
 -- 
 -- Created by SQL::Translator::Producer::SQLite
--- Created on Thu Oct  9 13:44:56 2008
+-- Created on Fri Oct 24 14:20:32 2008
 -- 
 BEGIN TRANSACTION;
 
@@ -171,11 +171,11 @@ CREATE INDEX fourkeys_to_twokeys_idx_t_artist_t_cd_fourkeys_to ON fourkeys_to_tw
 -- Table: genre
 --
 CREATE TABLE genre (
-  genreid  NOT NULL,
-  name  NOT NULL,
-  PRIMARY KEY (genreid)
+  genreid INTEGER PRIMARY KEY NOT NULL,
+  name varchar(100) NOT NULL
 );
 
+CREATE UNIQUE INDEX genre_name_genre ON genre (name);
 
 --
 -- Table: liner_notes