From: Matt S Trout Date: Fri, 20 Jan 2006 03:41:15 +0000 (+0000) Subject: register_resultset, Cursor fixes X-Git-Tag: v0.05005~117^2~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=71e65b395be8133d54b110a499f9e9619111c1f6;p=dbsrgits%2FDBIx-Class.git register_resultset, Cursor fixes --- diff --git a/lib/DBIx/Class/Relationship/Accessor.pm b/lib/DBIx/Class/Relationship/Accessor.pm index ca902b3..5c2c38d 100644 --- a/lib/DBIx/Class/Relationship/Accessor.pm +++ b/lib/DBIx/Class/Relationship/Accessor.pm @@ -3,14 +3,12 @@ package DBIx::Class::Relationship::Accessor; use strict; use warnings; -sub add_relationship { - my ($class, $rel, @rest) = @_; - my $ret = $class->next::method($rel => @rest); - my $rel_obj = $class->relationship_info($rel); - if (my $acc_type = $rel_obj->{attrs}{accessor}) { +sub register_relationship { + my ($class, $rel, $info) = @_; + if (my $acc_type = $info->{attrs}{accessor}) { $class->add_relationship_accessor($rel => $acc_type); } - return $ret; + $class->next::method($rel => $info); } sub add_relationship_accessor { diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index b662a23..c97635e 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -69,8 +69,14 @@ created, which calls C for the relationship. =back +=head2 register_relationship($relname, $rel_info) + +Registers a relationship on the class + =cut +sub register_relationship { } + =head2 search_related My::Table->search_related('relname', $cond, $attrs); diff --git a/lib/DBIx/Class/Relationship/CascadeActions.pm b/lib/DBIx/Class/Relationship/CascadeActions.pm index e1d1341..71a28c0 100644 --- a/lib/DBIx/Class/Relationship/CascadeActions.pm +++ b/lib/DBIx/Class/Relationship/CascadeActions.pm @@ -9,7 +9,8 @@ sub delete { my $ret = $self->next::method(@rest); - my %rels = map { $_ => $self->relationship_info($_) } $self->relationships; + my $source = $self->result_source; + my %rels = map { $_ => $source->relationship_info($_) } $source->relationships; my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels; foreach my $rel (@cascade) { $self->search_related($rel)->delete; @@ -24,7 +25,8 @@ sub update { my $ret = $self->next::method(@rest); - my %rels = map { $_ => $self->relationship_info($_) } $self->relationships; + my $source = $self->result_source; + my %rels = map { $_ => $source->relationship_info($_) } $source->relationships; my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels; foreach my $rel (@cascade) { $_->update for $self->$rel; diff --git a/lib/DBIx/Class/Relationship/ProxyMethods.pm b/lib/DBIx/Class/Relationship/ProxyMethods.pm index 7ac439b..03f32c4 100644 --- a/lib/DBIx/Class/Relationship/ProxyMethods.pm +++ b/lib/DBIx/Class/Relationship/ProxyMethods.pm @@ -5,14 +5,13 @@ use warnings; use base qw/DBIx::Class/; -sub add_relationship { - my ($class, $rel, @rest) = @_; - my $ret = $class->next::method($rel => @rest); - if (my $proxy_list = $class->relationship_info($rel)->{attrs}{proxy}) { +sub register_relationship { + my ($class, $rel, $info) = @_; + if (my $proxy_list = $info->{attrs}{proxy}) { $class->proxy_to_related($rel, (ref $proxy_list ? @$proxy_list : $proxy_list)); } - return $ret; + $class->next::method($rel, $info); } sub proxy_to_related { diff --git a/lib/DBIx/Class/ResultSourceInstance.pm b/lib/DBIx/Class/ResultSourceInstance.pm index 3b1a92e..e9fd560 100644 --- a/lib/DBIx/Class/ResultSourceInstance.pm +++ b/lib/DBIx/Class/ResultSourceInstance.pm @@ -40,7 +40,10 @@ sub set_primary_key { shift->result_source_instance->set_primary_key(@_); } sub primary_columns { shift->result_source_instance->primary_columns(@_); } sub add_relationship { - shift->result_source_instance->add_relationship(@_); + my ($class, $rel, @rest) = @_; + my $source = $class->result_source_instance; + $source->add_relationship($rel => @rest); + $class->register_relationship($rel => $source->relationship_info($rel)); } sub relationships { diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 21003db..a03a3d7 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -320,7 +320,7 @@ sub is_changed { Accessor to the ResultSource this object was created from -=head2 register_column +=head2 register_column($column, $column_info) Registers a column on the class and creates an accessor for it diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index 41b3da5..361b129 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -20,6 +20,7 @@ sub new { sub next { my ($self) = @_; if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) { + $self->{sth}->finish if $self->{sth}->{Active}; delete $self->{sth}; $self->{done} = 1; }