0.05999_01 shipped
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / LazyLoading.pm
CommitLineData
fe5d862b 1package DBIx::Class::CDBICompat::LazyLoading;
2
3use strict;
4use warnings;
5
a9433341 6sub resultset_instance {
7 my $self = shift;
8 my $rs = $self->next::method(@_);
5e8b1b2a 9 $rs = $rs->search(undef, { columns => [ $self->columns('Essential') ] });
a9433341 10 return $rs;
fe5d862b 11}
12
13sub get_column {
14 my ($self, $col) = @_;
15 if ((ref $self) && (!exists $self->{'_column_data'}{$col})
8d5134b0 16 && $self->{'_in_storage'}) {
fe5d862b 17 $self->_flesh(grep { exists $self->_column_groups->{$_}{$col}
18 && $_ ne 'All' }
19 keys %{ $self->_column_groups || {} });
20 }
147dd158 21 $self->next::method(@_[1..$#_]);
fe5d862b 22}
23
24sub _flesh {
25 my ($self, @groups) = @_;
b8e1e21f 26 @groups = ('All') unless @groups;
fe5d862b 27 my %want;
28 $want{$_} = 1 for map { keys %{$self->_column_groups->{$_}} } @groups;
29 if (my @want = grep { !exists $self->{'_column_data'}{$_} } keys %want) {
b98e75f6 30 my $cursor = $self->result_source->storage->select(
31 $self->result_source->name, \@want,
8b445e33 32 \$self->_ident_cond, { bind => [ $self->_ident_values ] });
33 #my $sth = $self->storage->select($self->_table_name, \@want,
34 # $self->ident_condition);
35 # Not sure why the first one works and this doesn't :(
223b8fe3 36 my @val = $cursor->next;
8b445e33 37#warn "Flesh: ".join(', ', @want, '=>', @val);
fe5d862b 38 foreach my $w (@want) {
39 $self->{'_column_data'}{$w} = shift @val;
40 }
41 }
42}
43
441;