Commit | Line | Data |
fe5d862b |
1 | package DBIx::Class::CDBICompat::LazyLoading; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a9433341 |
6 | sub resultset_instance { |
7 | my $self = shift; |
8 | my $rs = $self->next::method(@_); |
9 | $rs = $rs->search(undef, { cols => [ $self->columns('Essential') ] }); |
10 | return $rs; |
fe5d862b |
11 | } |
12 | |
13 | sub 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 | |
24 | sub _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 | |
44 | 1; |