Massive rewrite of bind handling, and overall simplification of ::Storage::DBI
[dbsrgits/DBIx-Class.git] / t / resultset / as_subselect_rs.t
CommitLineData
e4bb6727 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6
7use lib qw(t/lib);
8use DBICTest;
9use DBIC::SqlMakerTest;
10
11my $schema = DBICTest->init_schema();
12
13my $new_rs = $schema->resultset('Artist')->search({
14 'artwork_to_artist.artist_id' => 1
15}, {
16 join => 'artwork_to_artist'
17});
18lives_ok { $new_rs->count } 'regular search works';
19lives_ok { $new_rs->search({ 'artwork_to_artist.artwork_cd_id' => 1})->count }
20 '... and chaining off that using join works';
21lives_ok { $new_rs->search({ 'artwork_to_artist.artwork_cd_id' => 1})->as_subselect_rs->count }
22 '... and chaining off the virtual view works';
23dies_ok { $new_rs->as_subselect_rs->search({'artwork_to_artist.artwork_cd_id'=> 1})->count }
24 q{... but chaining off of a virtual view using join doesn't work};
ec781604 25
26my $book_rs = $schema->resultset ('BooksInLibrary')->search ({}, { join => 'owner' });
27
28is_same_sql_bind (
29 $book_rs->as_subselect_rs->as_query,
30 '(SELECT me.id, me.source, me.owner, me.title, me.price
31 FROM (
32 SELECT me.id, me.source, me.owner, me.title, me.price
33 FROM books me
34 JOIN owners owner ON owner.id = me.owner
35 WHERE ( source = ? )
36 ) me
37 )',
0e773352 38 [ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
39 => 'Library' ] ],
ec781604 40 'Resultset-class attributes do not seep outside of the subselect',
41);
42
e4bb6727 43done_testing;