dc0d50d793f1b171d292f76d3a7c8b9c1e02c6bd
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Artwork_to_Artist.pm
1 package # hide from PAUSE
2     DBICTest::Schema::Artwork_to_Artist;
3
4 use base qw/DBICTest::BaseResult/;
5 use Carp qw/confess/;
6
7 __PACKAGE__->table('artwork_to_artist');
8 __PACKAGE__->add_columns(
9   'artwork_cd_id' => {
10     data_type => 'integer',
11     is_foreign_key => 1,
12   },
13   'artist_id' => {
14     data_type => 'integer',
15     is_foreign_key => 1,
16   },
17 );
18 __PACKAGE__->set_primary_key(qw/artwork_cd_id artist_id/);
19 __PACKAGE__->belongs_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_cd_id');
20 __PACKAGE__->belongs_to('artist', 'DBICTest::Schema::Artist', 'artist_id');
21
22 __PACKAGE__->belongs_to('artist_test_m2m', 'DBICTest::Schema::Artist',
23   sub {
24     my $args = shift;
25
26     # This is for test purposes only. A regular user does not
27     # need to sanity check the passed-in arguments, this is what
28     # the tests are for :)
29     my @missing_args = grep { ! defined $args->{$_} }
30       qw/self_alias foreign_alias self_resultsource foreign_relname/;
31     confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
32       if @missing_args;
33
34     return (
35       { "$args->{foreign_alias}.artistid" => { -ident => "$args->{self_alias}.artist_id" },
36         "$args->{foreign_alias}.rank"     => { '<' => 10 },
37       },
38       $args->{self_rowobj} && {
39         "$args->{foreign_alias}.artistid" => $args->{self_rowobj}->artist_id,
40         "$args->{foreign_alias}.rank"   => { '<' => 10 },
41       }
42     );
43   }
44 );
45
46 __PACKAGE__->belongs_to('artist_test_m2m_noopt', 'DBICTest::Schema::Artist',
47   sub {
48     my $args = shift;
49
50     # This is for test purposes only. A regular user does not
51     # need to sanity check the passed-in arguments, this is what
52     # the tests are for :)
53     my @missing_args = grep { ! defined $args->{$_} }
54       qw/self_alias foreign_alias self_resultsource foreign_relname/;
55     confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
56       if @missing_args;
57
58     return (
59       { "$args->{foreign_alias}.artistid" => { -ident => "$args->{self_alias}.artist_id" },
60         "$args->{foreign_alias}.rank"     => { '<' => 10 },
61       }
62     );
63   }
64 );
65
66 1;