Commit | Line | Data |
8273e845 |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::CD; |
a02675cd |
3 | |
4a233f30 |
4 | use warnings; |
5 | use strict; |
6 | |
a3a17a15 |
7 | use base 'DBICTest::BaseResult'; |
8 | use DBICTest::Util 'check_customcond_args'; |
a02675cd |
9 | |
cebb7cce |
10 | # this tests table name as scalar ref |
11 | # DO NOT REMOVE THE \ |
12 | __PACKAGE__->table(\'cd'); |
13 | |
ff657a43 |
14 | __PACKAGE__->add_columns( |
0009fa49 |
15 | 'cdid' => { |
16 | data_type => 'integer', |
17 | is_auto_increment => 1, |
18 | }, |
19 | 'artist' => { |
20 | data_type => 'integer', |
21 | }, |
22 | 'title' => { |
23 | data_type => 'varchar', |
cb561d1a |
24 | size => 100, |
0009fa49 |
25 | }, |
26 | 'year' => { |
27 | data_type => 'varchar', |
cb561d1a |
28 | size => 100, |
0009fa49 |
29 | }, |
8273e845 |
30 | 'genreid' => { |
4e0eaf64 |
31 | data_type => 'integer', |
32 | is_nullable => 1, |
afa3668a |
33 | accessor => undef, |
a1cb5921 |
34 | }, |
35 | 'single_track' => { |
36 | data_type => 'integer', |
37 | is_nullable => 1, |
38 | is_foreign_key => 1, |
370f2ba2 |
39 | } |
0009fa49 |
40 | ); |
ff657a43 |
41 | __PACKAGE__->set_primary_key('cdid'); |
368a5228 |
42 | __PACKAGE__->add_unique_constraint([ qw/artist title/ ]); |
ff657a43 |
43 | |
8273e845 |
44 | __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, { |
45 | is_deferrable => 1, |
97c96475 |
46 | proxy => { artist_name => 'name' }, |
e377d723 |
47 | }); |
8273e845 |
48 | __PACKAGE__->belongs_to( very_long_artist_relationship => 'DBICTest::Schema::Artist', 'artist', { |
49 | is_deferrable => 1, |
e377d723 |
50 | }); |
ff657a43 |
51 | |
a1cb5921 |
52 | # in case this is a single-cd it promotes a track from another cd |
98fcc1c0 |
53 | __PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', |
54 | { 'foreign.trackid' => 'self.single_track' }, |
139e7991 |
55 | { join_type => 'left'}, |
56 | ); |
57 | |
58 | __PACKAGE__->belongs_to( single_track_opaque => 'DBICTest::Schema::Track', |
59 | sub { |
60 | my $args = &check_customcond_args; |
61 | \ " $args->{foreign_alias}.trackid = $args->{self_alias}.single_track "; |
62 | }, |
98fcc1c0 |
63 | { join_type => 'left'}, |
56b73f83 |
64 | ); |
a1cb5921 |
65 | |
3904d3c3 |
66 | # add a non-left single relationship for the complex prefetch tests |
98fcc1c0 |
67 | __PACKAGE__->belongs_to( existing_single_track => 'DBICTest::Schema::Track', |
68 | { 'foreign.trackid' => 'self.single_track' }, |
69 | ); |
3904d3c3 |
70 | |
ff657a43 |
71 | __PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' ); |
72 | __PACKAGE__->has_many( |
73 | tags => 'DBICTest::Schema::Tag', undef, |
74 | { order_by => 'tag' }, |
75 | ); |
76 | __PACKAGE__->has_many( |
77 | cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd' |
78 | ); |
79 | |
2053211a |
80 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys', 'cd' ); |
81 | |
82 | |
98fcc1c0 |
83 | # the undef condition in this rel is *deliberate* |
84 | # tests oddball legacy syntax |
ff657a43 |
85 | __PACKAGE__->might_have( |
86 | liner_notes => 'DBICTest::Schema::LinerNotes', undef, |
87 | { proxy => [ qw/notes/ ] }, |
88 | ); |
4f6386b0 |
89 | __PACKAGE__->might_have(artwork => 'DBICTest::Schema::Artwork', 'cd_id'); |
cc9d96d0 |
90 | __PACKAGE__->has_one(mandatory_artwork => 'DBICTest::Schema::Artwork', 'cd_id'); |
4f6386b0 |
91 | |
ff657a43 |
92 | __PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' ); |
93 | __PACKAGE__->many_to_many( |
94 | producers_sorted => cd_to_producer => 'producer', |
95 | { order_by => 'producer.name' }, |
96 | ); |
a02675cd |
97 | |
87310237 |
98 | __PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', |
98fcc1c0 |
99 | 'genreid', |
a0dd8679 |
100 | { |
101 | join_type => 'left', |
102 | on_delete => 'SET NULL', |
103 | on_update => 'CASCADE', |
a0dd8679 |
104 | }, |
87310237 |
105 | ); |
370f2ba2 |
106 | |
cef1bdda |
107 | #This second relationship was added to test the short-circuiting of pointless |
108 | #queries provided by undef_on_null_fk. the relevant test in 66relationship.t |
109 | __PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre', |
110 | { 'foreign.genreid' => 'self.genreid' }, |
111 | { |
112 | join_type => 'left', |
113 | on_delete => 'SET NULL', |
114 | on_update => 'CASCADE', |
115 | undef_on_null_fk => 0, |
116 | }, |
117 | ); |
118 | |
fe4118b1 |
119 | |
120 | # This is insane. Don't ever do anything like that |
121 | # This is for testing purposes only! |
122 | |
123 | # mst: mo: DBIC is an "object relational mapper" |
124 | # mst: mo: not an "object relational hider-because-mo-doesn't-understand-databases |
125 | # ribasushi: mo: try it with a subselect nevertheless, I'd love to be proven wrong |
126 | # ribasushi: mo: does sqlite actually take this? |
127 | # ribasushi: an order in a correlated subquery is insane - how long does it take you on real data? |
128 | |
129 | __PACKAGE__->might_have( |
130 | 'last_track', |
131 | 'DBICTest::Schema::Track', |
132 | sub { |
a3a17a15 |
133 | # This is for test purposes only. A regular user does not |
134 | # need to sanity check the passed-in arguments, this is what |
135 | # the tests are for :) |
136 | my $args = &check_customcond_args; |
137 | |
fe4118b1 |
138 | return ( |
139 | { |
140 | "$args->{foreign_alias}.trackid" => { '=' => |
141 | $args->{self_resultsource}->schema->resultset('Track')->search( |
142 | { 'correlated_tracks.cd' => { -ident => "$args->{self_alias}.cdid" } }, |
143 | { |
144 | order_by => { -desc => 'position' }, |
145 | rows => 1, |
146 | alias => 'correlated_tracks', |
147 | columns => ['trackid'] |
148 | }, |
149 | )->as_query |
150 | } |
151 | } |
152 | ); |
153 | }, |
154 | ); |
155 | |
a02675cd |
156 | 1; |