1 package DBIx::Class::CDBICompat::HasA;
7 my ($self, $col, $f_class, %args) = @_;
8 $self->throw( "No such column ${col}" ) unless $self->_columns->{$col};
9 eval "require $f_class";
10 if ($args{'inflate'} || $args{'deflate'}) { # Non-database has_a
11 if (!ref $args{'inflate'}) {
12 my $meth = $args{'inflate'};
13 $args{'inflate'} = sub { $f_class->$meth(shift); };
15 if (!ref $args{'deflate'}) {
16 my $meth = $args{'deflate'};
17 $args{'deflate'} = sub { shift->$meth; };
19 $self->inflate_column($col, \%args);
22 my ($pri, $too_many) = keys %{ $f_class->_primaries };
23 $self->throw( "has_a only works with a single primary key; ${f_class} has more. try using a belongs_to relationship instead of Class::DBI compat rels" )
26 $self->belongs_to($col, $f_class);