blib/lib/DBIO/Test/Schema/CD.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 86.6% 39 / 45 CC 1 SCAR 2.9
CC
1
Cov
90%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.3
« blib/lib/DBIO/Test/MooSchema/Result/CD.pm ↑ Summary blib/lib/DBIO/DeploymentHandler/VersionStorage/Standard/VersionResultSet.pm »
1 package DBIO::Test::Schema::CD;
2 # ABSTRACT: Test result class for the cd table
3  
4 256 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 256 our $VERSION = '0.900007';
7  
8 256 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 256 ▶use base 'DBIO::Test::BaseResult';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 256 ▶use DBIO::Test::Util 'check_customcond_args';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # this tests table name as scalar ref
14 # DO NOT REMOVE THE \
15 256 __PACKAGE__->table(\'cd');
16  
17 256 __PACKAGE__->add_columns(
18 'cdid' => {
19 data_type => 'integer',
20 is_auto_increment => 1,
21 },
22 'artist' => {
23 data_type => 'integer',
24 },
25 'title' => {
26 data_type => 'varchar',
27 size => 100,
28 },
29 'year' => {
30 data_type => 'varchar',
31 size => 100,
32 },
33 'genreid' => {
34 data_type => 'integer',
35 is_nullable => 1,
36 accessor => undef,
37 },
38 'single_track' => {
39 data_type => 'integer',
40 is_nullable => 1,
41 is_foreign_key => 1,
42 }
43 );
44 256 __PACKAGE__->set_primary_key('cdid');
45 256 __PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
46  
47 256 __PACKAGE__->belongs_to( artist => 'DBIO::Test::Schema::Artist', undef, {
48 is_deferrable => 1,
49 proxy => { artist_name => 'name' },
50 });
51 256 __PACKAGE__->belongs_to( very_long_artist_relationship => 'DBIO::Test::Schema::Artist', 'artist', {
52 is_deferrable => 1,
53 });
54  
55 # in case this is a single-cd it promotes a track from another cd
56 256 __PACKAGE__->belongs_to( single_track => 'DBIO::Test::Schema::Track',
57 { 'foreign.trackid' => 'self.single_track' },
58 { join_type => 'left'},
59 );
60  
61 __PACKAGE__->belongs_to( single_track_opaque => 'DBIO::Test::Schema::Track',
62 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 my $args = &check_customcond_args;
64 0 \ " $args->{foreign_alias}.trackid = $args->{self_alias}.single_track ";
65 },
66 256 { join_type => 'left'},
67 );
68  
69 # add a non-left single relationship for the complex prefetch tests
70 256 __PACKAGE__->belongs_to( existing_single_track => 'DBIO::Test::Schema::Track',
71 { 'foreign.trackid' => 'self.single_track' },
72 );
73  
74 256 __PACKAGE__->has_many( tracks => 'DBIO::Test::Schema::Track' );
75 256 __PACKAGE__->has_many(
76 tags => 'DBIO::Test::Schema::Tag', undef,
77 { order_by => 'tag' },
78 );
79 256 __PACKAGE__->has_many(
80 cd_to_producer => 'DBIO::Test::Schema::CD_to_Producer' => 'cd'
81 );
82  
83 256 __PACKAGE__->has_many( twokeys => 'DBIO::Test::Schema::TwoKeys', 'cd' );
84  
85  
86 # the undef condition in this rel is *deliberate*
87 # tests oddball legacy syntax
88 256 __PACKAGE__->might_have(
89 liner_notes => 'DBIO::Test::Schema::LinerNotes', undef,
90 { proxy => [ qw/notes/ ] },
91 );
92 256 __PACKAGE__->might_have(artwork => 'DBIO::Test::Schema::Artwork', 'cd_id');
93 256 __PACKAGE__->has_one(mandatory_artwork => 'DBIO::Test::Schema::Artwork', 'cd_id');
94  
95 256 __PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' );
96 256 __PACKAGE__->many_to_many(
97 producers_sorted => cd_to_producer => 'producer',
98 { order_by => 'producer.name' },
99 );
100  
101 256 __PACKAGE__->belongs_to('genre', 'DBIO::Test::Schema::Genre',
102 'genreid',
103 {
104 join_type => 'left',
105 on_delete => 'SET NULL',
106 on_update => 'CASCADE',
107 },
108 );
109  
110 #This second relationship was added to test the short-circuiting of pointless
111 #queries provided by undef_on_null_fk. the relevant test in 66relationship.t
112 256 __PACKAGE__->belongs_to('genre_inefficient', 'DBIO::Test::Schema::Genre',
113 { 'foreign.genreid' => 'self.genreid' },
114 {
115 join_type => 'left',
116 on_delete => 'SET NULL',
117 on_update => 'CASCADE',
118 undef_on_null_fk => 0,
119 },
120 );
121  
122  
123 # This is insane. Don't ever do anything like that
124 # This is for testing purposes only!
125  
126 # mst: mo: DBIO is an "object relational mapper"
127 # mst: mo: not an "object relational hider-because-mo-doesn't-understand-databases
128 # ribasushi: mo: try it with a subselect nevertheless, I'd love to be proven wrong
129 # ribasushi: mo: does sqlite actually take this?
130 # ribasushi: an order in a correlated subquery is insane - how long does it take you on real data?
131  
132 __PACKAGE__->might_have(
133 'last_track',
134 'DBIO::Test::Schema::Track',
135 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
136 # This is for test purposes only. A regular user does not
137 # need to sanity check the passed-in arguments, this is what
138 # the tests are for :)
139 0 my $args = &check_customcond_args;
140  
141 return (
142 {
143 "$args->{foreign_alias}.trackid" => { '=' =>
144 0 $args->{self_resultsource}->schema->resultset('Track')->search(
145 { 'correlated_tracks.cd' => { -ident => "$args->{self_alias}.cdid" } },
146 {
147 order_by => { -desc => 'position' },
148 rows => 1,
149 alias => 'correlated_tracks',
150 columns => ['trackid']
151 },
152 )->as_query
153 }
154 }
155 );
156 },
157 256 );
158  
159 256 1;
160  
161 __END__
« blib/lib/DBIO/Test/MooSchema/Result/CD.pm ↑ Summary blib/lib/DBIO/DeploymentHandler/VersionStorage/Standard/VersionResultSet.pm »