Paul Makepeace
+CL Kao
+
+Jess Robinson
+
+Marcus Ramberg
+
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
my ($from, $to) = split(/ /, $data);
my ($from_class, $to_class) = @{$self->{_classes}}{$from, $to};
my ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
- values %{ $from_class->_relationships };
+ map { $from_class->relationship_info($_) }
+ $from_class->relationships;
unless ($rel_obj) {
($from, $to) = ($to, $from);
($from_class, $to_class) = ($to_class, $from_class);
($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
- values %{ $from_class->_relationships };
+ map { $from_class->relationship_info($_) }
+ $from_class->relationships;
}
$self->throw( "No relationship to JOIN from ${from_class} to ${to_class}" )
unless $rel_obj;
__PACKAGE__->mk_classdata('_relationships', { } );
+sub relationships
+{
+ my $self = shift;
+
+ return keys %{$self->_relationships};
+}
+
+sub relationship_info
+{
+ my $self = shift;
+ my ($rel) = @_;
+
+ return $self->_relationships->{$rel};
+}
+
=head1 NAME
DBIx::Class::Relationship - Inter-table relationships
sub add_relationship {
my ($class, $rel, @rest) = @_;
my $ret = $class->next::method($rel => @rest);
- my $rel_obj = $class->_relationships->{$rel};
+ my $rel_obj = $class->relationship_info($rel);
if (my $acc_type = $rel_obj->{attrs}{accessor}) {
$class->add_relationship_accessor($rel => $acc_type);
}
} elsif ($acc_type eq 'filter') {
$class->throw("No such column $rel to filter")
unless $class->has_column($rel);
- my $f_class = $class->_relationships->{$rel}{class};
+ my $f_class = $class->relationship_info($rel)->{class};
$class->inflate_column($rel,
{ inflate => sub {
my ($val, $self) = @_;
return map { $class->_resolve_join($_, $alias) } @$join;
} elsif (ref $join eq 'HASH') {
return map { $class->_resolve_join($_, $alias),
- $class->_relationships->{$_}{class}->_resolve_join($join->{$_}, $_) }
+ $class->relationship_info($_)->{class}->_resolve_join($join->{$_}, $_) }
keys %$join;
} elsif (ref $join) {
$class->throw("No idea how to resolve join reftype ".ref $join);
} else {
- my $rel_obj = $class->_relationships->{$join};
+ my $rel_obj = $class->relationship_info($join);
$class->throw("No such relationship ${join}") unless $rel_obj;
my $j_class = $rel_obj->{class};
my %join = (_action => 'join',
if (@_ > 1 && ref $_[$#_] eq 'HASH') {
$attrs = { %{ pop(@_) } };
}
- my $rel_obj = $self->_relationships->{$rel};
+ my $rel_obj = $self->relationship_info($rel);
$self->throw( "No such relationship ${rel}" ) unless $rel_obj;
$attrs = { %{$rel_obj->{attrs} || {}}, %{$attrs || {}} };
sub set_from_related {
my ($self, $rel, $f_obj) = @_;
- my $rel_obj = $self->_relationships->{$rel};
+ my $rel_obj = $self->relationship_info($rel);
$self->throw( "No such relationship ${rel}" ) unless $rel_obj;
my $cond = $rel_obj->{cond};
$self->throw( "set_from_related can only handle a hash condition; the "
my $ret = $self->next::method(@rest);
- my %rels = %{ $self->_relationships };
+ my %rels = map { $_ => $self->relationship_info($_) } $self->relationships;
my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
foreach my $rel (@cascade) {
$self->search_related($rel)->delete;
my $ret = $self->next::method(@rest);
- my %rels = %{ $self->_relationships };
+ my %rels = map { $_ => $self->relationship_info($_) } $self->relationships;
my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
foreach my $rel (@cascade) {
$_->update for $self->$rel;
sub add_relationship {
my ($class, $rel, @rest) = @_;
my $ret = $class->next::method($rel => @rest);
- if (my $proxy_list = $class->_relationships->{$rel}->{attrs}{proxy}) {
+ if (my $proxy_list = $class->relationship_info($rel)->{attrs}{proxy}) {
$class->proxy_to_related($rel,
(ref $proxy_list ? @$proxy_list : $proxy_list));
}
unless $seen{$pre};
my @pre =
map { "$pre.$_" }
- $source->result_class->_relationships->{$pre}->{class}->columns;
+ $source->result_class->relationship_info($pre)->{class}->columns;
push(@{$attrs->{select}}, @pre);
push(@{$attrs->{as}}, @pre);
}
sub search_related {
my ($self, $rel, @rest) = @_;
- my $rel_obj = $self->{source}->result_class->_relationships->{$rel};
+ my $rel_obj = $self->{source}->result_class->relationship_info($rel);
$self->{source}->result_class->throw(
"No such relationship ${rel} in search_related")
unless $rel_obj;
ref $class || $class);
my $schema;
PRE: foreach my $pre (keys %{$prefetch||{}}) {
- my $rel_obj = $class->_relationships->{$pre};
+ my $rel_obj = $class->relationship_info($pre);
+ die "Can't prefetch non-eistant relationship ${pre}" unless $rel_obj;
$schema ||= $new->result_source->schema;
my $pre_class = $schema->class($rel_obj->{class});
my $fetched = $pre_class->inflate_result(@{$prefetch->{$pre}});