[Jifty-commit] jifty-dbi branch, master, updated. 0.72-1-g203f8bb
Jifty commits
jifty-commit at lists.jifty.org
Sat Dec 3 09:44:21 EST 2011
The branch, master has been updated
via 203f8bb34973aeb3c1e8baa65816346fb12eccfd (commit)
from d4cf855c5dd76268fe8ab657a4b45c818fd9f1cf (commit)
Summary of changes:
lib/Jifty/DBI/Collection.pm | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 203f8bb34973aeb3c1e8baa65816346fb12eccfd
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Sat Dec 3 09:44:11 2011 -0500
Allow prefetching of only a subset of the other table's columns
diff --git a/lib/Jifty/DBI/Collection.pm b/lib/Jifty/DBI/Collection.pm
index 3b9081e..265a747 100755
--- a/lib/Jifty/DBI/Collection.pm
+++ b/lib/Jifty/DBI/Collection.pm
@@ -508,7 +508,9 @@ sub query_columns {
$reference = $class;
}
- push @cols, $self->_qualified_record_columns( $alias => $reference );
+ my $only_cols = $prefetch_related{$alias}{columns};
+
+ push @cols, $self->_qualified_record_columns( $alias => $reference, $only_cols );
}
return CORE::join( ', ', @cols );
}
@@ -535,8 +537,13 @@ sub _qualified_record_columns {
my $self = shift;
my $alias = shift;
my $item = shift;
- return map $alias ."." . $_ ." as ". $alias ."_". $_,
- map $_->name, grep { !$_->virtual && !$_->computed } $item->columns;
+ my $only_cols = shift;
+ my @columns = map { $_->name } grep { !$_->virtual && !$_->computed } $item->columns;
+ if ($only_cols) {
+ my %wanted = map { +($_ => 1) } @{ $only_cols };
+ @columns = grep { $wanted{$_} } @columns;
+ }
+ return map {$alias ."." . $_ ." as ". $alias ."_". $_} @columns
}
=head2 prefetch PARAMHASH
@@ -603,6 +610,7 @@ sub prefetch {
name => undef,
class => undef,
reference => undef,
+ columns => undef,
@_,
);
@@ -641,7 +649,7 @@ sub prefetch {
$self->prefetch_related( {} ) unless $self->prefetch_related;
$self->prefetch_related->{ $args{alias} } = {};
$self->prefetch_related->{ $args{alias} }{$_} = $args{$_}
- for qw/alias class name/;
+ for qw/alias class name columns/;
# Return the alias, in case we made it
return $args{alias};
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list