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