Commit | Line | Data |
b28cc0ba |
1 | package DBIx::Class::CDBICompat::MightHave; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | sub might_have { |
7 | my ($class, $rel, $f_class, @columns) = @_; |
8 | my ($pri, $too_many) = keys %{ $class->_primaries }; |
9 | $class->throw( "might_have only works with a single primary key; ${class} has more" ) |
10 | if $too_many; |
11 | my $f_pri; |
12 | ($f_pri, $too_many) = keys %{ $f_class->_primaries }; |
13 | $class->throw( "might_have only works with a single primary key; ${f_class} has more" ) |
14 | if $too_many; |
15 | $class->add_relationship($rel, $f_class, |
16 | { "foreign.${f_pri}" => "self.${pri}" }, |
17 | { accessor => 'single', proxy => \@columns, |
18 | cascade_update => 1, cascade_delete => 1 }); |
19 | 1; |
20 | } |
21 | |
22 | 1; |