X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FLazyLoading.pm;h=0817ef24f30254d1f5c3be950a6d1b8adf0e40a5;hb=bca6956d7eb1196ae767271688f915d7ab078a10;hp=add9390af0d0a5ce66d55f14bc1c7b7c536be87e;hpb=e60dc79fcd4d6318e83584b826526e65048b86a9;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/LazyLoading.pm b/lib/DBIx/Class/CDBICompat/LazyLoading.pm index add9390..0817ef2 100644 --- a/lib/DBIx/Class/CDBICompat/LazyLoading.pm +++ b/lib/DBIx/Class/CDBICompat/LazyLoading.pm @@ -11,6 +11,47 @@ sub resultset_instance { return $rs; } + +# 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; +} + + +# And again for create +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); + + return $obj; +} + + +sub _clear_column_data { + my $self = shift; + + delete $self->{_column_data}{$_} for @_; + delete $self->{_inflated_column}{$_} for @_; +} + + sub get_column { my ($self, $col) = @_; if ((ref $self) && (!exists $self->{'_column_data'}{$col}) @@ -30,7 +71,7 @@ sub copy { for my $col ($self->primary_columns) { $changes->{$col} = undef unless exists $changes->{$col}; } - + return $self->next::method($changes); } @@ -62,7 +103,9 @@ sub _flesh { # $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; }