FAQ update: Minor correction from Richard Jolly, mention search_rs, wrap lines, and...
[dbsrgits/DBIx-Class.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
25sub _flesh {
26 my ($self, @groups) = @_;
b8e1e21f 27 @groups = ('All') unless @groups;
fe5d862b 28 my %want;
29 $want{$_} = 1 for map { keys %{$self->_column_groups->{$_}} } @groups;
30 if (my @want = grep { !exists $self->{'_column_data'}{$_} } keys %want) {
b98e75f6 31 my $cursor = $self->result_source->storage->select(
32 $self->result_source->name, \@want,
8b445e33 33 \$self->_ident_cond, { bind => [ $self->_ident_values ] });
34 #my $sth = $self->storage->select($self->_table_name, \@want,
35 # $self->ident_condition);
36 # Not sure why the first one works and this doesn't :(
223b8fe3 37 my @val = $cursor->next;
8b445e33 38#warn "Flesh: ".join(', ', @want, '=>', @val);
fe5d862b 39 foreach my $w (@want) {
40 $self->{'_column_data'}{$w} = shift @val;
41 }
42 }
43}
44
451;