X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FLazyLoading.pm;h=0b6691b412bd75e33ff741eb14987d9dadf12df0;hb=895b576d77f033255f80ebf7464a7f3f198ac98a;hp=ff235e2b8797f6971a85a5a06c64310c7b6ffb7f;hpb=b98e75f625eb5474f43a046ba7bedff770214f8e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/LazyLoading.pm b/lib/DBIx/Class/CDBICompat/LazyLoading.pm index ff235e2..0b6691b 100644 --- a/lib/DBIx/Class/CDBICompat/LazyLoading.pm +++ b/lib/DBIx/Class/CDBICompat/LazyLoading.pm @@ -1,12 +1,33 @@ -package DBIx::Class::CDBICompat::LazyLoading; +package # hide from PAUSE + DBIx::Class::CDBICompat::LazyLoading; use strict; use warnings; -sub _select_columns { - return shift->columns('Essential'); +sub resultset_instance { + my $self = shift; + my $rs = $self->next::method(@_); + $rs = $rs->search(undef, { columns => [ $self->columns('Essential') ] }); + 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(@_); + + delete $self->{_column_data}{$_} for @dirty_columns; + delete $self->{_inflated_column}{$_} for @dirty_columns; + + return $ret; +} + + sub get_column { my ($self, $col) = @_; if ((ref $self) && (!exists $self->{'_column_data'}{$col}) @@ -18,6 +39,33 @@ sub get_column { $self->next::method(@_[1..$#_]); } +# CDBI does not explicitly declare auto increment columns, so +# we just clear out our primary columns before copying. +sub copy { + my($self, $changes) = @_; + + for my $col ($self->primary_columns) { + $changes->{$col} = undef unless exists $changes->{$col}; + } + + return $self->next::method($changes); +} + +sub discard_changes { + my($self) = shift; + + delete $self->{_column_data}{$_} for $self->is_changed; + delete $self->{_dirty_columns}; + delete $self->{_relationship_data}; + + return $self; +} + +sub _ident_cond { + my ($class) = @_; + return join(" AND ", map { "$_ = ?" } $class->primary_columns); +} + sub _flesh { my ($self, @groups) = @_; @groups = ('All') unless @groups;