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