1 package # hide from PAUSE
2 DBIx::Class::CDBICompat::LazyLoading;
7 sub resultset_instance {
9 my $rs = $self->next::method(@_);
10 $rs = $rs->search(undef, { columns => [ $self->columns('Essential') ] });
15 # Emulate that CDBI throws out all changed columns and reloads them on
16 # request in case the database modifies the new value (say, via a trigger)
20 my @dirty_columns = keys %{$self->{_dirty_columns}};
22 my $ret = $self->next::method(@_);
23 $self->_clear_column_data(@dirty_columns);
29 # And again for create
34 my @columns = keys %$data;
36 my $obj = $class->next::method(@_);
37 return $obj unless defined $obj;
39 my %primary_cols = map { $_ => 1 } $class->primary_columns;
40 my @data_cols = grep !$primary_cols{$_}, @columns;
41 $obj->_clear_column_data(@data_cols);
47 sub _clear_column_data {
50 delete $self->{_column_data}{$_} for @_;
51 delete $self->{_inflated_column}{$_} for @_;
56 my ($self, $col) = @_;
57 if ((ref $self) && (!exists $self->{'_column_data'}{$col})
58 && $self->{'_in_storage'}) {
59 $self->_flesh(grep { exists $self->_column_groups->{$_}{$col}
61 keys %{ $self->_column_groups || {} });
63 $self->next::method(@_[1..$#_]);
66 # CDBI does not explicitly declare auto increment columns, so
67 # we just clear out our primary columns before copying.
69 my($self, $changes) = @_;
71 for my $col ($self->primary_columns) {
72 $changes->{$col} = undef unless exists $changes->{$col};
75 return $self->next::method($changes);
81 delete $self->{_column_data}{$_} for $self->is_changed;
82 delete $self->{_dirty_columns};
83 delete $self->{_relationship_data};
90 return join(" AND ", map { "$_ = ?" } $class->primary_columns);
94 my ($self, @groups) = @_;
95 @groups = ('All') unless @groups;
97 $want{$_} = 1 for map { keys %{$self->_column_groups->{$_}} } @groups;
98 if (my @want = grep { !exists $self->{'_column_data'}{$_} } keys %want) {
99 my $cursor = $self->result_source->storage->select(
100 $self->result_source->name, \@want,
101 \$self->_ident_cond, { bind => [ $self->_ident_values ] });
102 #my $sth = $self->storage->select($self->_table_name, \@want,
103 # $self->ident_condition);
104 # Not sure why the first one works and this doesn't :(
105 my @val = $cursor->next;
107 return unless @val; # object must have been deleted from the database
109 foreach my $w (@want) {
110 $self->{'_column_data'}{$w} = shift @val;