Emulate the Class::DBI::Relationship object returned from C<meta_info()>.
-The C<args()> method does not return any useful result as it's not clear what it should contain nor if any of the information is applicable to DBIx::Class.
-
=cut
my %method2key = (
class => 'self_class',
accessor => 'accessor',
foreign_class => 'class',
+ args => 'args',
);
sub new {
*{$method} = $code;
}
-sub args {
- warn "args() is unlikely to ever work";
- return undef;
-}
-
-
1;
$self->throw_exception( "No such column ${col}" ) unless $self->has_column($col);
$self->ensure_class_loaded($f_class);
- my $rel;
+ my $rel_info;
if ($args{'inflate'} || $args{'deflate'}) { # Non-database has_a
if (!ref $args{'inflate'}) {
}
$self->inflate_column($col, \%args);
- $rel = {
+ $rel_info = {
class => $f_class
};
}
else {
$self->belongs_to($col, $f_class);
- $rel = $self->result_source_instance->relationship_info($col);
+ $rel_info = $self->result_source_instance->relationship_info($col);
}
+ $rel_info->{args} = \%args;
+
$self->_extend_meta(
has_a => $col,
- $rel
+ $rel_info
);
return 1;
$class->next::method($rel, $f_class, $f_key, $args);
+ my $rel_info = $class->result_source_instance->relationship_info($rel);
+ $args->{mapping} = \@f_method;
+ $args->{foreign_key} = $f_key;
+ $rel_info->{args} = $args;
+
$class->_extend_meta(
has_many => $rel,
- $class->result_source_instance->relationship_info($rel)
+ $rel_info
);
if (@f_method) {
$ret = $class->next::method($rel, $f_class, undef,
{ proxy => \@columns });
}
-
+
+ my $rel_info = $class->result_source_instance->relationship_info($rel);
+ $rel_info->{args}{import} = \@columns;
+
$class->_extend_meta(
might_have => $rel,
- $class->result_source_instance->relationship_info($rel)
+ $rel_info
);
return $ret;
package Temp::DBI;
use base qw(DBIx::Class::CDBICompat);
Temp::DBI->columns(All => qw(id date));
-Temp::DBI->has_a( date => 'Time::Piece', inflate => sub {
- Time::Piece->strptime(shift, "%Y-%m-%d")
-});
+
+my $strptime_inflate = sub {
+ Time::Piece->strptime(shift, "%Y-%m-%d")
+};
+Temp::DBI->has_a(
+ date => 'Time::Piece',
+ inflate => $strptime_inflate
+);
package Temp::Person;
{
my $owners = Temp::Pet->meta_info( has_many => 'owners' );
- warning_like {
- local $TODO = 'args is unlikely to ever work';
- is_deeply $owners->args, {
- foreign_key => 'pet',
- mapping => [],
- order_by => undef
- };
- } qr/^\Qargs() is unlikely to ever work/;
+ is_deeply $owners->args, {
+ foreign_key => 'pet',
+ mapping => [],
+ };
}
{
is $date->class, 'Temp::DBI';
is $date->foreign_class, 'Time::Piece';
is $date->accessor, 'date';
+ is $date->args->{inflate}, $strptime_inflate;
}