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