Merge 'trunk' into 'DBIx-Class-current'
Brandon L. Black [Tue, 8 Aug 2006 06:32:12 +0000 (06:32 +0000)]
r9285@moloko (orig r2671):  blblack | 2006-08-08 00:59:05 -0500
using ->rows here was not a reliable thing to do
r9286@moloko (orig r2672):  dwc | 2006-08-08 01:27:30 -0500
Remove extraneous sources for aliasing test; same effect can be achieved using search_related

lib/DBIx/Class/Storage/DBI.pm
t/64db.t
t/79aliasing.t
t/lib/DBICTest.pm
t/lib/DBICTest/Schema.pm
t/lib/DBICTest/Schema/Agent.pm [deleted file]
t/lib/DBICTest/Schema/Artist.pm
t/lib/DBICTest/Schema/Label.pm [deleted file]
t/lib/sqlite.sql

index 36f69ee..d2da6bc 100644 (file)
@@ -884,7 +884,7 @@ sub __columns_info_for {
         $result{$col_name} = \%column_info;
       }
     };
-    return \%result if !$@;
+    return \%result if !$@ && scalar keys %result;
   }
 
   my %result;
index 47aff46..d9c03aa 100644 (file)
--- a/t/64db.t
+++ b/t/64db.t
@@ -41,7 +41,6 @@ my $type_info = $schema->storage->columns_info_for('artist');
 
 delete $type_info->{artistid}{size};
 delete $type_info->{name}{size};
-delete $type_info->{agent}{size};
 
 my $test_type_info = {
     'artistid' => {
@@ -52,10 +51,6 @@ my $test_type_info = {
         'data_type' => 'varchar',
         'is_nullable' => 0,
     },
-    'agent' => {
-        'data_type' => 'integer',
-        'is_nullable' => 0,
-    },
 };
 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
 
index e0eb04c..6e73f10 100644 (file)
@@ -9,34 +9,38 @@ my $schema = DBICTest->init_schema();
 
 plan tests => 8;
 
-my $label = $schema->resultset('Label')->find({ labelid => 1 });
+my $artist = $schema->resultset('Artist')->find(1);
 
 # Check that you can leave off the alias
 {
-  my $existing_agent = $label->agents->find_or_create({
-    name => 'Ted',
+  my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+    title => 'Ted',
+    year  => 2006,
   });
-  ok(! $existing_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
-  is($existing_agent->name, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry');
+  ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+  is($existing_cd->title, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry');
 
-  my $new_agent = $label->agents->find_or_create({
-    name => 'Someone Else',
+  my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+    title => 'Something Else',
+    year  => 2006,
   });
-  ok(! $new_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
-  is($new_agent->name, 'Someone Else', 'find_or_create on prefetched has_many with same column names: name matches');
+  ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+  is($new_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: title matches');
 }
 
 # Check that you can specify the alias
 {
-  my $existing_agent = $label->agents->find_or_create({
-    'me.name' => 'Someone Else',
+  my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+    'me.title' => 'Something Else',
+    'me.year'  => 2006,
   });
-  ok(! $existing_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
-  is($existing_agent->name, 'Someone Else', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for existing entry');
+  ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+  is($existing_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for existing entry');
 
-  my $new_agent = $label->agents->find_or_create({
-    'me.name' => 'Some New Guy',
+  my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+    'me.title' => 'Some New Guy',
+    'me.year'  => 2006,
   });
-  ok(! $new_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
-  is($new_agent->name, 'Some New Guy', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for new entry');
+  ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+  is($new_cd->title, 'Some New Guy', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for new entry');
 }
index e691999..a050862 100755 (executable)
@@ -104,21 +104,11 @@ sub populate_schema {
     my $self = shift;
     my $schema = shift;
 
-    $schema->populate('Label', [
-        [ qw/labelid name/ ],
-        [ 1, 'Acme Records' ],
-    ]);
-
-    $schema->populate('Agent', [
-        [ qw/agentid label name/ ],
-        [ 1, 1, 'Ted' ],
-    ]);
-
     $schema->populate('Artist', [
-        [ qw/artistid agent name/ ],
-        [ 1, 1, 'Caterwauler McCrae' ],
-        [ 2, 1, 'Random Boy Band' ],
-        [ 3, 1, 'We Are Goth' ],
+        [ qw/artistid name/ ],
+        [ 1, 'Caterwauler McCrae' ],
+        [ 2, 'Random Boy Band' ],
+        [ 3, 'We Are Goth' ],
     ]);
 
     $schema->populate('CD', [
index f8b9816..8e7597d 100644 (file)
@@ -6,11 +6,9 @@ use base qw/DBIx::Class::Schema/;
 no warnings qw/qw/;
 
 __PACKAGE__->load_classes(qw/
-  Agent
   Artist
   Employee
   CD
-  Label
   Link
   Bookmark
   #dummy
diff --git a/t/lib/DBICTest/Schema/Agent.pm b/t/lib/DBICTest/Schema/Agent.pm
deleted file mode 100644 (file)
index 6434393..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package # hide from PAUSE 
-    DBICTest::Schema::Agent;
-
-use base 'DBIx::Class::Core';
-
-__PACKAGE__->table('agent');
-__PACKAGE__->add_columns(
-  'agentid' => {
-    data_type         => 'integer',
-    is_auto_increment => 1
-  },
-  'label' => {
-    data_type => 'integer',
-  },
-  'name' => {
-    data_type   => 'varchar',
-    size        => 100,
-    is_nullable => 1,
-  },
-);
-__PACKAGE__->set_primary_key('agentid');
-
-__PACKAGE__->has_many( artists => 'DBICTest::Schema::Artist' );
-__PACKAGE__->belongs_to( label => 'DBICTest::Schema::Label' );
-
-1;
index 66d15b5..0bb49c4 100644 (file)
@@ -9,10 +9,6 @@ __PACKAGE__->add_columns(
     data_type => 'integer',
     is_auto_increment => 1
   },
-  'agent' => {
-    data_type   => 'integer',
-    is_nullable => 1,
-  },
   'name' => {
     data_type => 'varchar',
     size      => 100,
@@ -23,7 +19,6 @@ __PACKAGE__->set_primary_key('artistid');
 
 __PACKAGE__->mk_classdata('field_name_for', {
     artistid    => 'primary key',
-    agent       => 'agent',
     name        => 'artist name',
 });
 
@@ -32,8 +27,6 @@ __PACKAGE__->has_many(
     { order_by => 'year' },
 );
 
-__PACKAGE__->belongs_to( agent => 'DBICTest::Schema::Agent' );
-
 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
 
diff --git a/t/lib/DBICTest/Schema/Label.pm b/t/lib/DBICTest/Schema/Label.pm
deleted file mode 100644 (file)
index 2d79bf4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package # hide from PAUSE 
-    DBICTest::Schema::Label;
-
-use base 'DBIx::Class::Core';
-
-__PACKAGE__->table('label');
-__PACKAGE__->add_columns(
-  'labelid' => {
-    data_type         => 'integer',
-    is_auto_increment => 1
-  },
-  'name' => {
-    data_type   => 'varchar',
-    size        => 100,
-    is_nullable => 1,
-  },
-);
-__PACKAGE__->set_primary_key('labelid');
-
-__PACKAGE__->has_many(
-  agents => 'DBICTest::Schema::Agent',
-  undef,
-  { prefetch => 'artists' }
-);
-
-1;
index 5846973..228e448 100644 (file)
@@ -1,6 +1,6 @@
 -- 
 -- Created by SQL::Translator::Producer::SQLite
--- Created on Fri Aug  4 19:03:21 2006
+-- Created on Tue Aug  8 01:53:20 2006
 -- 
 BEGIN TRANSACTION;
 
@@ -44,15 +44,6 @@ CREATE TABLE cd_to_producer (
 --
 CREATE TABLE artist (
   artistid INTEGER PRIMARY KEY NOT NULL,
-  agent integer,
-  name varchar(100)
-);
-
---
--- Table: label
---
-CREATE TABLE label (
-  labelid INTEGER PRIMARY KEY NOT NULL,
   name varchar(100)
 );
 
@@ -128,24 +119,6 @@ CREATE TABLE self_ref (
 );
 
 --
--- Table: tags
---
-CREATE TABLE tags (
-  tagid INTEGER PRIMARY KEY NOT NULL,
-  cd integer NOT NULL,
-  tag varchar(100) NOT NULL
-);
-
---
--- Table: agent
---
-CREATE TABLE agent (
-  agentid INTEGER PRIMARY KEY NOT NULL,
-  label integer NOT NULL,
-  name varchar(100)
-);
-
---
 -- Table: link
 --
 CREATE TABLE link (
@@ -155,6 +128,15 @@ CREATE TABLE link (
 );
 
 --
+-- Table: tags
+--
+CREATE TABLE tags (
+  tagid INTEGER PRIMARY KEY NOT NULL,
+  cd integer NOT NULL,
+  tag varchar(100) NOT NULL
+);
+
+--
 -- Table: treelike
 --
 CREATE TABLE treelike (