Move find_co_root into DBICTest::Util
[dbsrgits/DBIx-Class.git] / t / relationship / custom_opaque.t
CommitLineData
139e7991 1use strict;
2use warnings;
3
4use Test::More;
5
6use lib 't/lib';
7use DBICTest;
8
9my $schema = DBICTest->init_schema( no_populate => 1, quote_names => 1 );
10
11$schema->resultset('CD')->create({
12 title => 'Equinoxe',
13 year => 1978,
14 artist => { name => 'JMJ' },
15 genre => { name => 'electro' },
16 tracks => [
17 { title => 'e1' },
18 { title => 'e2' },
19 { title => 'e3' },
20 ],
21 single_track => {
22 title => 'o1',
23 cd => {
24 title => 'Oxygene',
25 year => 1976,
26 artist => { name => 'JMJ' },
27 },
28 },
29});
30
31my $cd = $schema->resultset('CD')->search({ single_track => { '!=', undef } })->first;
32
33$schema->is_executed_sql_bind(
34 sub { is( eval{$cd->single_track_opaque->title}, 'o1', 'Found correct single track' ) },
35 [
36 [
37 'SELECT "me"."trackid", "me"."cd", "me"."position", "me"."title", "me"."last_updated_on", "me"."last_updated_at"
38 FROM cd "cd__row"
39 JOIN "track" "me"
40 ON me.trackid = cd__row.single_track
41 WHERE "cd__row"."cdid" = ?
42 ',
43 [
44 { dbic_colname => "cd__row.cdid", sqlt_datatype => "integer" }
45 => 2
46 ]
47 ],
48 ],
49);
50
51done_testing;