Commit | Line | Data |
b8e1e21f |
1 | package DBIx::Class::CDBICompat::HasA; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | sub has_a { |
4a07648a |
7 | my ($self, $col, $f_class, %args) = @_; |
78bab9ca |
8 | $self->throw( "No such column ${col}" ) unless $self->_columns->{$col}; |
b8e1e21f |
9 | eval "require $f_class"; |
22b15c96 |
10 | if ($args{'inflate'} || $args{'deflate'}) { # Non-database has_a |
4a07648a |
11 | if (!ref $args{'inflate'}) { |
12 | my $meth = $args{'inflate'}; |
13 | $args{'inflate'} = sub { $f_class->$meth(shift); }; |
14 | } |
15 | if (!ref $args{'deflate'}) { |
16 | my $meth = $args{'deflate'}; |
17 | $args{'deflate'} = sub { shift->$meth; }; |
18 | } |
19 | $self->inflate_column($col, \%args); |
20 | return 1; |
21 | } |
b8e1e21f |
22 | my ($pri, $too_many) = keys %{ $f_class->_primaries }; |
22b15c96 |
23 | $self->throw( "has_a only works with a single primary key; ${f_class} has more. try using a has_one relationship instead of Class::DBI compat rels" ) |
b8e1e21f |
24 | if $too_many; |
22b15c96 |
25 | |
26 | $self->has_one($col, $f_class); |
b8e1e21f |
27 | return 1; |
28 | } |
29 | |
b8e1e21f |
30 | 1; |