From: Peter Rabbitson Date: Mon, 26 Aug 2013 11:10:59 +0000 (+0200) Subject: Update example Result classes for proper DDL generation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=20bfea3fd35252310456e125e8dfe948f6c675c2;p=dbsrgits%2FDBIx-Class-Historic.git Update example Result classes for proper DDL generation Also given that this is one of the first things a newbie sees, it is prudent to stick to canonical definition --- diff --git a/examples/Schema/MyApp/Schema/Result/Artist.pm b/examples/Schema/MyApp/Schema/Result/Artist.pm index 61a11f2..70074b1 100644 --- a/examples/Schema/MyApp/Schema/Result/Artist.pm +++ b/examples/Schema/MyApp/Schema/Result/Artist.pm @@ -3,14 +3,24 @@ package MyApp::Schema::Result::Artist; use warnings; use strict; -use base qw/DBIx::Class::Core/; +use base qw( DBIx::Class::Core ); __PACKAGE__->table('artist'); -__PACKAGE__->add_columns(qw/ artistid name /); +__PACKAGE__->add_columns( + artistid => { + data_type => 'integer', + is_auto_increment => 1 + }, + name => { + data_type => 'text', + }, +); __PACKAGE__->set_primary_key('artistid'); +__PACKAGE__->add_unique_constraint([qw( name )]); + __PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd'); 1; diff --git a/examples/Schema/MyApp/Schema/Result/Cd.pm b/examples/Schema/MyApp/Schema/Result/Cd.pm index 6d600a1..9b0602c 100644 --- a/examples/Schema/MyApp/Schema/Result/Cd.pm +++ b/examples/Schema/MyApp/Schema/Result/Cd.pm @@ -3,14 +3,31 @@ package MyApp::Schema::Result::Cd; use warnings; use strict; -use base qw/DBIx::Class::Core/; +use base qw( DBIx::Class::Core ); __PACKAGE__->table('cd'); -__PACKAGE__->add_columns(qw/ cdid artist title year /); +__PACKAGE__->add_columns( + cdid => { + data_type => 'integer', + is_auto_increment => 1 + }, + artist => { + data_type => 'integer', + }, + title => { + data_type => 'text', + }, + year => { + data_type => 'datetime', + is_nullable => 1, + }, +); __PACKAGE__->set_primary_key('cdid'); +__PACKAGE__->add_unique_constraint([qw( title artist )]); + __PACKAGE__->belongs_to('artist' => 'MyApp::Schema::Result::Artist'); __PACKAGE__->has_many('tracks' => 'MyApp::Schema::Result::Track'); diff --git a/examples/Schema/MyApp/Schema/Result/Track.pm b/examples/Schema/MyApp/Schema/Result/Track.pm index 91b8368..dc0951a 100644 --- a/examples/Schema/MyApp/Schema/Result/Track.pm +++ b/examples/Schema/MyApp/Schema/Result/Track.pm @@ -3,14 +3,27 @@ package MyApp::Schema::Result::Track; use warnings; use strict; -use base qw/DBIx::Class::Core/; +use base qw( DBIx::Class::Core ); __PACKAGE__->table('track'); -__PACKAGE__->add_columns(qw/ trackid cd title/); +__PACKAGE__->add_columns( + trackid => { + data_type => 'integer', + is_auto_increment => 1 + }, + cd => { + data_type => 'integer', + }, + title => { + data_type => 'text', + }, +); __PACKAGE__->set_primary_key('trackid'); +__PACKAGE__->add_unique_constraint([qw( title cd )]); + __PACKAGE__->belongs_to('cd' => 'MyApp::Schema::Result::Cd'); 1;