From: Rafael Kitover Date: Mon, 29 Jun 2009 19:39:26 +0000 (+0000) Subject: separated table ref test out, changed CDTableRef to a view with less rels X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=688e73cb3072b07c340b654422c323dd2769f064;p=dbsrgits%2FDBIx-Class-Historic.git separated table ref test out, changed CDTableRef to a view with less rels --- diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index 7c2d3f2..f0c34a9 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -11,7 +11,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 9 ); + : ( tests => 7 ); } use_ok('DBICTest'); @@ -46,27 +46,6 @@ is_same_sql_bind( 'got correct SQL for count query with quoting' ); -# try with ->table(\'cd') should NOT be quoted -$rs = $schema->resultset('CDTableRef')->search( - { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, - { join => 'artist' }); -eval { $rs->count }; -is_same_sql_bind( - $sql, \@bind, - "SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"], - 'got correct SQL for count query with quoting' -); - -# check that the table works -eval { - my $rs = $schema->resultset('CDTableRef'); - $rs->create({ cdid => 6, artist => 3, title => 'mtfnpy', year => 2009 }); - my $row = $rs->find(6); - $row->update({ title => 'bleh' }); - $row->delete; -}; -ok !$@, 'operations on scalarref table name work'; - my $order = 'year DESC'; $rs = $schema->resultset('CD')->search({}, { 'order_by' => $order }); diff --git a/t/19table_name_ref.t b/t/19table_name_ref.t new file mode 100644 index 0000000..d98e8a7 --- /dev/null +++ b/t/19table_name_ref.t @@ -0,0 +1,45 @@ +use strict; +use warnings; + +use Test::More; +use IO::File; + +use lib qw(t/lib); +use DBICTest; +use DBIC::SqlMakerTest; +use DBIC::DebugObj; + +plan tests => 2; + +my $schema = DBICTest->init_schema(); + +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); + +my ($sql, @bind); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), +$schema->storage->debug(1); + +my $rs; + +# ->table(\'cd') should NOT be quoted +$rs = $schema->resultset('CDTableRef')->search( + { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, + { join => 'artist' }); +eval { $rs->count }; +is_same_sql_bind( + $sql, \@bind, + "SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"], + 'got correct SQL for count query with quoting' +); + +# check that the table works +eval { + $rs = $schema->resultset('CDTableRef'); + $rs->create({ cdid => 6, artist => 3, title => 'mtfnpy', year => 2009 }); + my $row = $rs->find(6); + $row->update({ title => 'bleh' }); + $row->delete; +}; +ok !$@, 'operations on scalarref table name work'; +diag $@ if $@; diff --git a/t/lib/DBICTest/Schema/CDTableRef.pm b/t/lib/DBICTest/Schema/CDTableRef.pm index b29fb3f..239d294 100644 --- a/t/lib/DBICTest/Schema/CDTableRef.pm +++ b/t/lib/DBICTest/Schema/CDTableRef.pm @@ -2,8 +2,11 @@ package # hide from PAUSE DBICTest::Schema::CDTableRef; use base qw/DBICTest::BaseResult/; +use DBIx::Class::ResultSource::View; +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); __PACKAGE__->table(\'cd'); +__PACKAGE__->result_source_instance->is_virtual(0); __PACKAGE__->add_columns( 'cdid' => { @@ -39,51 +42,4 @@ __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', is_deferrable => 1, }); -# in case this is a single-cd it promotes a track from another cd -__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', 'single_track', - { join_type => 'left'} -); - -__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track', 'cd' ); -__PACKAGE__->has_many( - tags => 'DBICTest::Schema::Tag', 'cd', - { order_by => 'tag' }, -); -__PACKAGE__->has_many( - cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd' -); - -__PACKAGE__->might_have( - liner_notes => 'DBICTest::Schema::LinerNotes', undef, - { proxy => [ qw/notes/ ] }, -); -__PACKAGE__->might_have(artwork => 'DBICTest::Schema::Artwork', 'cd_id'); - -__PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' ); -__PACKAGE__->many_to_many( - producers_sorted => cd_to_producer => 'producer', - { order_by => 'producer.name' }, -); - -__PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', - { 'foreign.genreid' => 'self.genreid' }, - { - join_type => 'left', - on_delete => 'SET NULL', - on_update => 'CASCADE', - }, -); - -#This second relationship was added to test the short-circuiting of pointless -#queries provided by undef_on_null_fk. the relevant test in 66relationship.t -__PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre', - { 'foreign.genreid' => 'self.genreid' }, - { - join_type => 'left', - on_delete => 'SET NULL', - on_update => 'CASCADE', - undef_on_null_fk => 0, - }, -); - 1;