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' }, |
55 | { join_type => 'left'}, |
56b73f83 |
56 | ); |
a1cb5921 |
57 | |
3904d3c3 |
58 | # add a non-left single relationship for the complex prefetch tests |
98fcc1c0 |
59 | __PACKAGE__->belongs_to( existing_single_track => 'DBICTest::Schema::Track', |
60 | { 'foreign.trackid' => 'self.single_track' }, |
61 | ); |
3904d3c3 |
62 | |
ff657a43 |
63 | __PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' ); |
64 | __PACKAGE__->has_many( |
65 | tags => 'DBICTest::Schema::Tag', undef, |
66 | { order_by => 'tag' }, |
67 | ); |
68 | __PACKAGE__->has_many( |
69 | cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd' |
70 | ); |
71 | |
2053211a |
72 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys', 'cd' ); |
73 | |
74 | |
98fcc1c0 |
75 | # the undef condition in this rel is *deliberate* |
76 | # tests oddball legacy syntax |
ff657a43 |
77 | __PACKAGE__->might_have( |
78 | liner_notes => 'DBICTest::Schema::LinerNotes', undef, |
79 | { proxy => [ qw/notes/ ] }, |
80 | ); |
4f6386b0 |
81 | __PACKAGE__->might_have(artwork => 'DBICTest::Schema::Artwork', 'cd_id'); |
cc9d96d0 |
82 | __PACKAGE__->has_one(mandatory_artwork => 'DBICTest::Schema::Artwork', 'cd_id'); |
4f6386b0 |
83 | |
ff657a43 |
84 | __PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' ); |
85 | __PACKAGE__->many_to_many( |
86 | producers_sorted => cd_to_producer => 'producer', |
87 | { order_by => 'producer.name' }, |
88 | ); |
a02675cd |
89 | |
87310237 |
90 | __PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', |
98fcc1c0 |
91 | 'genreid', |
a0dd8679 |
92 | { |
93 | join_type => 'left', |
94 | on_delete => 'SET NULL', |
95 | on_update => 'CASCADE', |
a0dd8679 |
96 | }, |
87310237 |
97 | ); |
370f2ba2 |
98 | |
cef1bdda |
99 | #This second relationship was added to test the short-circuiting of pointless |
100 | #queries provided by undef_on_null_fk. the relevant test in 66relationship.t |
101 | __PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre', |
102 | { 'foreign.genreid' => 'self.genreid' }, |
103 | { |
104 | join_type => 'left', |
105 | on_delete => 'SET NULL', |
106 | on_update => 'CASCADE', |
107 | undef_on_null_fk => 0, |
108 | }, |
109 | ); |
110 | |
fe4118b1 |
111 | |
112 | # This is insane. Don't ever do anything like that |
113 | # This is for testing purposes only! |
114 | |
115 | # mst: mo: DBIC is an "object relational mapper" |
116 | # mst: mo: not an "object relational hider-because-mo-doesn't-understand-databases |
117 | # ribasushi: mo: try it with a subselect nevertheless, I'd love to be proven wrong |
118 | # ribasushi: mo: does sqlite actually take this? |
119 | # ribasushi: an order in a correlated subquery is insane - how long does it take you on real data? |
120 | |
121 | __PACKAGE__->might_have( |
122 | 'last_track', |
123 | 'DBICTest::Schema::Track', |
124 | sub { |
a3a17a15 |
125 | # This is for test purposes only. A regular user does not |
126 | # need to sanity check the passed-in arguments, this is what |
127 | # the tests are for :) |
128 | my $args = &check_customcond_args; |
129 | |
fe4118b1 |
130 | return ( |
131 | { |
132 | "$args->{foreign_alias}.trackid" => { '=' => |
133 | $args->{self_resultsource}->schema->resultset('Track')->search( |
134 | { 'correlated_tracks.cd' => { -ident => "$args->{self_alias}.cdid" } }, |
135 | { |
136 | order_by => { -desc => 'position' }, |
137 | rows => 1, |
138 | alias => 'correlated_tracks', |
139 | columns => ['trackid'] |
140 | }, |
141 | )->as_query |
142 | } |
143 | } |
144 | ); |
145 | }, |
146 | ); |
147 | |
a02675cd |
148 | 1; |