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