1 package # hide from PAUSE
7 use base qw/DBICTest::BaseResult/;
9 # this tests table name as scalar ref
11 __PACKAGE__->table(\'cd');
13 __PACKAGE__->add_columns(
15 data_type => 'integer',
16 is_auto_increment => 1,
19 data_type => 'integer',
22 data_type => 'varchar',
26 data_type => 'varchar',
30 data_type => 'integer',
35 data_type => 'integer',
40 __PACKAGE__->set_primary_key('cdid');
41 __PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
43 __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, {
45 proxy => { artist_name => 'name' },
47 __PACKAGE__->belongs_to( very_long_artist_relationship => 'DBICTest::Schema::Artist', 'artist', {
51 # in case this is a single-cd it promotes a track from another cd
52 __PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', 'single_track',
53 { join_type => 'left'}
56 # add a non-left single relationship for the complex prefetch tests
57 __PACKAGE__->belongs_to( existing_single_track => 'DBICTest::Schema::Track', 'single_track');
59 __PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' );
60 __PACKAGE__->has_many(
61 tags => 'DBICTest::Schema::Tag', undef,
62 { order_by => 'tag' },
64 __PACKAGE__->has_many(
65 cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd'
68 __PACKAGE__->might_have(
69 liner_notes => 'DBICTest::Schema::LinerNotes', undef,
70 { proxy => [ qw/notes/ ] },
72 __PACKAGE__->might_have(artwork => 'DBICTest::Schema::Artwork', 'cd_id');
73 __PACKAGE__->has_one(mandatory_artwork => 'DBICTest::Schema::Artwork', 'cd_id');
75 __PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' );
76 __PACKAGE__->many_to_many(
77 producers_sorted => cd_to_producer => 'producer',
78 { order_by => 'producer.name' },
81 __PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre',
82 { 'foreign.genreid' => 'self.genreid' },
85 on_delete => 'SET NULL',
86 on_update => 'CASCADE',
90 #This second relationship was added to test the short-circuiting of pointless
91 #queries provided by undef_on_null_fk. the relevant test in 66relationship.t
92 __PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre',
93 { 'foreign.genreid' => 'self.genreid' },
96 on_delete => 'SET NULL',
97 on_update => 'CASCADE',
98 undef_on_null_fk => 0,
103 # This is insane. Don't ever do anything like that
104 # This is for testing purposes only!
106 # mst: mo: DBIC is an "object relational mapper"
107 # mst: mo: not an "object relational hider-because-mo-doesn't-understand-databases
108 # ribasushi: mo: try it with a subselect nevertheless, I'd love to be proven wrong
109 # ribasushi: mo: does sqlite actually take this?
110 # ribasushi: an order in a correlated subquery is insane - how long does it take you on real data?
112 __PACKAGE__->might_have(
114 'DBICTest::Schema::Track',
119 "$args->{foreign_alias}.trackid" => { '=' =>
120 $args->{self_resultsource}->schema->resultset('Track')->search(
121 { 'correlated_tracks.cd' => { -ident => "$args->{self_alias}.cdid" } },
123 order_by => { -desc => 'position' },
125 alias => 'correlated_tracks',
126 columns => ['trackid']