Merge 'trunk' into 'count_distinct'
Justin Hunter [Sat, 2 May 2009 08:36:02 +0000 (08:36 +0000)]
r5987@mullet (orig r5986):  castaway | 2009-04-25 02:59:28 -0700
Docs on using multiple db schemas (from abraxxa maybe, I forget)
Docs on setting result_class from agaran

r5988@mullet (orig r5987):  ribasushi | 2009-04-27 01:03:58 -0700
Refactor the (almost obsolete) DBD::SQLite check not to fork() within win32
r5989@mullet (orig r5988):  ribasushi | 2009-04-27 01:05:43 -0700
Whops, we don't exit under win32
r5990@mullet (orig r5989):  ribasushi | 2009-04-27 01:14:38 -0700
More AUTHOR dependencies pulled from Replicated.pm
Up MI version to 0.79 (not going further as auto_install is broken again, need a permanent solution)
Reorder configure_requires() as per Alias
Remove Meta_TupleKeys munging as per Alias
r5991@mullet (orig r5990):  ribasushi | 2009-04-27 02:11:15 -0700
Release 0.08101
r5995@mullet (orig r5994):  arcanez | 2009-04-28 00:05:53 -0700
change from DB::Schema to My::Schema
add ::Result:: as necessary (load_namespaces instead of load_classes)

r5996@mullet (orig r5995):  ribasushi | 2009-04-28 02:12:33 -0700
Fix a todo and some minor test adjustments
r5997@mullet (orig r5996):  ribasushi | 2009-04-28 02:35:31 -0700
Bogus test dependency
r6003@mullet (orig r6002):  arcanez | 2009-04-28 13:20:42 -0700
fix for columns => [ ... ] issue
r6014@mullet (orig r6013):  arcanez | 2009-04-28 16:16:48 -0700
test for prefetch by columns
r6016@mullet (orig r6015):  ribasushi | 2009-04-29 01:22:16 -0700
test and patch for failing mini-prefetch via columns (arcanez++)
r6017@mullet (orig r6016):  ribasushi | 2009-04-29 01:23:25 -0700
Add two TODOs by arcanez (not sure about those)
r6018@mullet (orig r6017):  ribasushi | 2009-04-29 01:24:20 -0700
Add TODOs illustrating a problem with as_query
r6019@mullet (orig r6018):  arcanez | 2009-04-29 05:47:03 -0700
untodo/fix test
r6020@mullet (orig r6019):  ribasushi | 2009-04-29 06:39:27 -0700
Strip out inane todo
r6021@mullet (orig r6020):  ribasushi | 2009-04-29 06:40:03 -0700
Forgotten debugging
r6022@mullet (orig r6021):  ribasushi | 2009-04-29 06:41:37 -0700
Fixes to massive breakage introduced by 5948  ribasushi--
r6023@mullet (orig r6022):  ribasushi | 2009-04-29 06:47:23 -0700
Changes
r6024@mullet (orig r6023):  jasonmay | 2009-04-29 08:18:11 -0700
allow multiple classless sources to be registered without dying

r6025@mullet (orig r6024):  jasonmay | 2009-04-29 09:47:26 -0700
add jasonmay to list of contributors

r6034@mullet (orig r6033):  ribasushi | 2009-04-29 23:53:51 -0700
Add tests for r6002
r6036@mullet (orig r6035):  ribasushi | 2009-04-30 01:12:23 -0700
Revert addition of superficial relationship in r5886
r6039@mullet (orig r6038):  ribasushi | 2009-04-30 01:28:04 -0700
Release 0.08102

1  2 
lib/DBIx/Class/ResultSet.pm

@@@ -307,7 -307,7 +307,7 @@@ sub search_rs 
    my $new_attrs = { %{$our_attrs}, %{$attrs} };
  
    # merge new attrs into inherited
 -  foreach my $key (qw/join prefetch +select +as/) {
 +  foreach my $key (qw/join prefetch +select +as bind/) {
      next unless exists $attrs->{$key};
      $new_attrs->{$key} = $self->_merge_attr($our_attrs->{$key}, $attrs->{$key});
    }
@@@ -1121,6 -1121,11 +1121,11 @@@ An accessor for the class to use when c
  C<< result_source->result_class >> - which in most cases is the name of the 
  L<"table"|DBIx::Class::Manual::Glossary/"ResultSource"> class.
  
+ Note that changing the result_class will also remove any components
+ that were originally loaded in the source class via
+ L<DBIx::Class::ResultSource/load_components>. Any overloaded methods
+ in the original source class will not run.
  =cut
  
  sub result_class {
@@@ -1146,6 -1151,12 +1151,6 @@@ Performs an SQL C<COUNT> with the same 
  with to find the number of elements. If passed arguments, does a search
  on the resultset and counts the results of that.
  
 -Note: When using C<count> with C<group_by>, L<DBIx::Class> emulates C<GROUP BY>
 -using C<COUNT( DISTINCT( columns ) )>. Some databases (notably SQLite) do
 -not support C<DISTINCT> with multiple columns. If you are using such a
 -database, you should only use columns from the main table in your C<group_by>
 -clause.
 -
  =cut
  
  sub count {
  
  sub _count { # Separated out so pager can get the full count
    my $self = shift;
 -  my $select = { count => '*' };
 -
    my $attrs = { %{$self->_resolved_attrs} };
 -  if (my $group_by = delete $attrs->{group_by}) {
 -    delete $attrs->{having};
 -    my @distinct = (ref $group_by ?  @$group_by : ($group_by));
 -    # todo: try CONCAT for multi-column pk
 -    my @pk = $self->result_source->primary_columns;
 -    if (@pk == 1) {
 -      my $alias = $attrs->{alias};
 -      foreach my $column (@distinct) {
 -        if ($column =~ qr/^(?:\Q${alias}.\E)?$pk[0]$/) {
 -          @distinct = ($column);
 -          last;
 -        }
 -      }
 -    }
  
 -    $select = { count => { distinct => \@distinct } };
 +  if (my $group_by = $attrs->{group_by}) {
 +    delete $attrs->{order_by};
 +
 +    $attrs->{select} = $group_by; 
 +    $attrs->{from} = [ { 'mesub' => (ref $self)->new($self->result_source, $attrs)->cursor->as_query } ];
 +    delete $attrs->{where};
    }
  
 -  $attrs->{select} = $select;
 +  $attrs->{select} = { count => '*' };
    $attrs->{as} = [qw/count/];
  
 -  # offset, order by and page are not needed to count. record_filter is cdbi
 -  delete $attrs->{$_} for qw/rows offset order_by page pager record_filter/;
 +  # offset, order by, group by, where and page are not needed to count. record_filter is cdbi
 +  delete $attrs->{$_} for qw/rows offset order_by group_by page pager record_filter/;
  
    my $tmp_rs = (ref $self)->new($self->result_source, $attrs);
    my ($count) = $tmp_rs->cursor->next;
@@@ -2382,12 -2404,20 +2387,20 @@@ sub _resolved_attrs 
    # build columns (as long as select isn't set) into a set of as/select hashes
    unless ( $attrs->{select} ) {
        @colbits = map {
-           ( ref($_) eq 'HASH' ) ? $_
-             : {
-               (
-                   /^\Q${alias}.\E(.+)$/ ? $1
-                   : $_
-                 ) => ( /\./ ? $_ : "${alias}.$_" )
+           ( ref($_) eq 'HASH' )
+               ? $_
+               : {
+                   (
+                     /^\Q${alias}.\E(.+)$/ 
+                       ? "$1"
+                       : "$_"
+                   )
+                 => 
+                   (
+                     /\./ 
+                       ? "$_" 
+                       : "${alias}.$_"
+                   )
              }
        } ( ref($attrs->{columns}) eq 'ARRAY' ) ? @{ delete $attrs->{columns}} : (delete $attrs->{columns} || $source->columns );
    }