X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FLazyLoading.pm;h=d14b4b74843e530fd8f7fed3fd7d087177cfc7c5;hb=dc7d89911b7bb98c30208cf73af522a99998dcd6;hp=e8ffbccd69ef40047322f2f1f519824af776ade9;hpb=1d7e89b8623b1ae271aac80651d16dc7c655b15a;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/LazyLoading.pm b/lib/DBIx/Class/CDBICompat/LazyLoading.pm index e8ffbcc..d14b4b7 100644 --- a/lib/DBIx/Class/CDBICompat/LazyLoading.pm +++ b/lib/DBIx/Class/CDBICompat/LazyLoading.pm @@ -4,24 +4,25 @@ package # hide from PAUSE use strict; use warnings; +use base 'DBIx::Class'; + sub resultset_instance { my $self = shift; - my $rs = $self->next::method(@_); - $rs = $rs->search(undef, { columns => [ $self->columns('Essential') ] }); - return $rs; + $self->next::method(@_) + ->search_rs(undef, { columns => [ $self->columns('Essential') ] }); } -# Emulate that CDBI throws out all changed columns and reloads them on +# Emulate that CDBI throws out all changed columns and reloads them on # request in case the database modifies the new value (say, via a trigger) sub update { my $self = shift; - + my @dirty_columns = keys %{$self->{_dirty_columns}}; - + my $ret = $self->next::method(@_); $self->_clear_column_data(@dirty_columns); - + return $ret; } @@ -30,12 +31,12 @@ sub update { sub create { my $class = shift; my($data) = @_; - + my @columns = keys %$data; - + my $obj = $class->next::method(@_); return $obj unless defined $obj; - + my %primary_cols = map { $_ => 1 } $class->primary_columns; my @data_cols = grep !$primary_cols{$_}, @columns; $obj->_clear_column_data(@data_cols); @@ -46,7 +47,7 @@ sub create { sub _clear_column_data { my $self = shift; - + delete $self->{_column_data}{$_} for @_; delete $self->{_inflated_column}{$_} for @_; } @@ -71,7 +72,7 @@ sub copy { for my $col ($self->primary_columns) { $changes->{$col} = undef unless exists $changes->{$col}; } - + return $self->next::method($changes); } @@ -96,14 +97,16 @@ sub _flesh { my %want; $want{$_} = 1 for map { keys %{$self->_column_groups->{$_}} } @groups; if (my @want = grep { !exists $self->{'_column_data'}{$_} } keys %want) { - my $cursor = $self->result_source->storage->select( + my $cursor = $self->result_source->schema->storage->select( $self->result_source->name, \@want, \$self->_ident_cond, { bind => [ $self->_ident_values ] }); #my $sth = $self->storage->select($self->_table_name, \@want, # $self->ident_condition); # Not sure why the first one works and this doesn't :( my @val = $cursor->next; -#warn "Flesh: ".join(', ', @want, '=>', @val); + + return unless @val; # object must have been deleted from the database + foreach my $w (@want) { $self->{'_column_data'}{$w} = shift @val; }