separated table ref test out, changed CDTableRef to a view with less rels
[dbsrgits/DBIx-Class.git] / t / 19table_name_ref.t
CommitLineData
688e73cb 1use strict;
2use warnings;
3
4use Test::More;
5use IO::File;
6
7use lib qw(t/lib);
8use DBICTest;
9use DBIC::SqlMakerTest;
10use DBIC::DebugObj;
11
12plan tests => 2;
13
14my $schema = DBICTest->init_schema();
15
16$schema->storage->sql_maker->quote_char('`');
17$schema->storage->sql_maker->name_sep('.');
18
19my ($sql, @bind);
20$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
21$schema->storage->debug(1);
22
23my $rs;
24
25# ->table(\'cd') should NOT be quoted
26$rs = $schema->resultset('CDTableRef')->search(
27 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
28 { join => 'artist' });
29eval { $rs->count };
30is_same_sql_bind(
31 $sql, \@bind,
32 "SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
33 'got correct SQL for count query with quoting'
34);
35
36# check that the table works
37eval {
38 $rs = $schema->resultset('CDTableRef');
39 $rs->create({ cdid => 6, artist => 3, title => 'mtfnpy', year => 2009 });
40 my $row = $rs->find(6);
41 $row->update({ title => 'bleh' });
42 $row->delete;
43};
44ok !$@, 'operations on scalarref table name work';
45diag $@ if $@;