X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRow.pm;h=a34a1d8f1f1b09d37b5bf20b2ce302fd03c32ce4;hb=4376a1574bc5b25f4b9160e8fc3ce329ae226e0f;hp=b8c4da715ab1e600a659fd9b395da773f4d20971;hpb=a85b7ebe9762ca64a08468f6c8f27a0ae583d38c;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index b8c4da7..a34a1d8 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -21,7 +21,7 @@ BEGIN { : sub () { 0 }; } -__PACKAGE__->mk_group_accessors('simple' => qw/_source_handle/); +__PACKAGE__->mk_group_accessors('simple' => [result_source => '_result_source']); =head1 NAME @@ -64,12 +64,12 @@ this class, you are better off calling it on a L object. When calling it directly, you will not get a complete, usable row -object until you pass or set the C attribute, to a +object until you pass or set the C attribute, to a L instance that is attached to a L with a valid connection. C<$attrs> is a hashref of column name, value data. It can also contain -some other attributes such as the C. +some other attributes such as the C. Passing an object, or an arrayref of objects as a value will call L for you. When @@ -160,28 +160,23 @@ sub new { my ($class, $attrs) = @_; $class = ref $class if ref $class; - my $new = { - _column_data => {}, - }; - bless $new, $class; - - if (my $handle = delete $attrs->{-source_handle}) { - $new->_source_handle($handle); - } - - my $source; - if ($source = delete $attrs->{-result_source}) { - $new->result_source($source); - } - - if (my $related = delete $attrs->{-cols_from_relations}) { - @{$new->{_ignore_at_insert}={}}{@$related} = (); - } + my $new = bless { _column_data => {} }, $class; if ($attrs) { $new->throw_exception("attrs must be a hashref") unless ref($attrs) eq 'HASH'; + my $source = delete $attrs->{-result_source}; + if ( my $h = delete $attrs->{-source_handle} ) { + $source ||= $h->resolve; + } + + $new->result_source($source) if $source; + + if (my $col_from_rel = delete $attrs->{-cols_from_relations}) { + @{$new->{_ignore_at_insert}={}}{@$col_from_rel} = (); + } + my ($related,$inflated); foreach my $key (keys %$attrs) { @@ -516,12 +511,12 @@ this method. sub update { my ($self, $upd) = @_; - my $ident_cond = $self->{_orig_ident} || $self->ident_condition; - $self->set_inflated_columns($upd) if $upd; - my %to_update = $self->get_dirty_columns; - return $self unless keys %to_update; + my %to_update = $self->get_dirty_columns + or return $self; + + my $ident_cond = $self->{_orig_ident} || $self->ident_condition; $self->throw_exception( "Not in database" ) unless $self->in_storage; $self->throw_exception($self->{_orig_ident_failreason}) @@ -821,9 +816,13 @@ sub _is_column_numeric { my $colinfo = $self->column_info ($column); # cache for speed (the object may *not* have a resultsource instance) - if (! defined $colinfo->{is_numeric} && $self->_source_handle) { + if ( + ! defined $colinfo->{is_numeric} + and + my $storage = try { $self->result_source->schema->storage } + ) { $colinfo->{is_numeric} = - $self->result_source->schema->storage->is_datatype_numeric ($colinfo->{data_type}) + $storage->is_datatype_numeric ($colinfo->{data_type}) ? 1 : 0 ; @@ -880,11 +879,31 @@ sub set_column { : 1 ; - # FIXME sadly the update code just checks for keys, not for their value - $self->{_dirty_columns}{$column} = 1 if $dirty; + if ($dirty) { + # FIXME sadly the update code just checks for keys, not for their value + $self->{_dirty_columns}{$column} = 1; + + # Clear out the relation/inflation cache related to this column + # + # FIXME - this is a quick *largely incorrect* hack, pending a more + # serious rework during the merge of single and filter rels + my $rels = $self->result_source->{_relationships}; + for my $rel (keys %$rels) { - # XXX clear out the relation cache for this column - delete $self->{related_resultsets}{$column}; + my $acc = $rels->{$rel}{attrs}{accessor} || ''; + + if ( $acc eq 'single' and $rels->{$rel}{attrs}{fk_columns}{$column} ) { + delete $self->{related_resultsets}{$rel}; + delete $self->{_relationship_data}{$rel}; + #delete $self->{_inflated_column}{$rel}; + } + elsif ( $acc eq 'filter' and $rel eq $column) { + delete $self->{related_resultsets}{$rel}; + #delete $self->{_relationship_data}{$rel}; + delete $self->{_inflated_column}{$rel}; + } + } + } return $new_value; } @@ -1122,20 +1141,13 @@ L, see L. sub inflate_result { my ($class, $source, $me, $prefetch) = @_; - my ($source_handle) = $source; - - if ($source->isa('DBIx::Class::ResultSourceHandle')) { - $source = $source_handle->resolve - } - else { - $source_handle = $source->handle - } + $source = $source->resolve + if $source->isa('DBIx::Class::ResultSourceHandle'); - my $new = { - _source_handle => $source_handle, - _column_data => $me, - }; - bless $new, (ref $class || $class); + my $new = bless + { _column_data => $me, _result_source => $source }, + ref $class || $class + ; foreach my $pre (keys %{$prefetch||{}}) { @@ -1270,7 +1282,7 @@ sub is_column_changed { =over -=item Arguments: none +=item Arguments: $result_source_instance =item Returns: a ResultSource instance @@ -1278,18 +1290,6 @@ sub is_column_changed { Accessor to the L this object was created from. -=cut - -sub result_source { - my $self = shift; - - if (@_) { - $self->_source_handle($_[0]->handle); - } else { - $self->_source_handle->resolve; - } -} - =head2 register_column $column_info = { .... }; @@ -1438,8 +1438,8 @@ See L. sub throw_exception { my $self=shift; - if (ref $self && ref $self->result_source && $self->result_source->schema) { - $self->result_source->schema->throw_exception(@_) + if (ref $self && ref $self->result_source ) { + $self->result_source->throw_exception(@_) } else { DBIx::Class::Exception->throw(@_);