X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource%2FRowParser.pm;h=fa69299f8dd22565ba5b2e5009a0b92b198a4089;hb=5b3090637dc0ea8949627267561820b43ff8e1cb;hp=cc4706cde4541a16e552968619a09546077abeb6;hpb=3d8caf63b7fa6f2adf9bbd1f49bc7ad932d031b6;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSource/RowParser.pm b/lib/DBIx/Class/ResultSource/RowParser.pm index cc4706c..fa69299 100644 --- a/lib/DBIx/Class/ResultSource/RowParser.pm +++ b/lib/DBIx/Class/ResultSource/RowParser.pm @@ -93,40 +93,50 @@ sub _resolve_prefetch { # any sort of adjustment/rewrite should be relatively easy (fsvo relatively) # sub _mk_row_parser { - my ($self, $args) = @_; - - my $val_index = { map - { $args->{inflate_map}[$_] => $_ } - ( 0 .. $#{$args->{inflate_map}} ) - }; - - if (! $args->{collapse} ) { - return assemble_simple_parser({ - val_index => $val_index, - }); - } - else { - my $collapse_map = $self->_resolve_collapse ({ - premultiplied => $args->{premultiplied}, - # FIXME - # only consider real columns (not functions) during collapse resolution - # this check shouldn't really be here, as fucktards are not supposed to - # alias random crap to existing column names anyway, but still - just in - # case - # FIXME !!!! - this does not yet deal with unbalanced selectors correctly - # (it is now trivial as the attrs specify where things go out of sync - # needs MOAR tests) - as => { map - { ref $args->{selection}[$val_index->{$_}] ? () : ( $_ => $val_index->{$_} ) } - keys %$val_index - } - }); - - return assemble_collapsing_parser({ - val_index => $val_index, - collapse_map => $collapse_map, - }); - } + # $args and $attrs are seperated to delineate what is core collapser stuff and + # what is dbic $rs specific + my ($self, $args, $attrs) = @_; + + die "HRI without pruning makes zero sense" + if ( $args->{hri_style} && ! $args->{prune_null_branches} ); + + my %common = ( + hri_style => $args->{hri_style}, + prune_null_branches => $args->{prune_null_branches}, + val_index => { map + { $args->{inflate_map}[$_] => $_ } + ( 0 .. $#{$args->{inflate_map}} ) + }, + ); + + my $src = $args->{collapse} + ? assemble_collapsing_parser({ + %common, + collapse_map => $self->_resolve_collapse ({ + # FIXME + # only consider real columns (not functions) during collapse resolution + # this check shouldn't really be here, as fucktards are not supposed to + # alias random crap to existing column names anyway, but still - just in + # case + # FIXME !!!! - this does not yet deal with unbalanced selectors correctly + # (it is now trivial as the attrs specify where things go out of sync + # needs MOAR tests) + as => { map + { ref $attrs->{select}[$common{val_index}{$_}] ? () : ( $_ => $common{val_index}{$_} ) } + keys %{$common{val_index}} + }, + premultiplied => $args->{premultiplied}, + }) + }) + : assemble_simple_parser( + \%common + ) + ; + + return $args->{eval} + ? ( eval "sub $src" || die $@ ) + : $src + ; } @@ -199,13 +209,14 @@ sub _resolve_collapse { } } - # if the parent is already defined, assume all of its related FKs are selected + # if the parent is already defined *AND* we have an inner reverse relationship + # (i.e. do not exist without it) , assume all of its related FKs are selected # (even if they in fact are NOT in the select list). Keep a record of what we # assumed, and if any such phantom-column becomes part of our own collapser, # throw everything assumed-from-parent away and replace with the collapser of # the parent (whatever it may be) my $assumed_from_parent; - unless ($args->{_parent_info}{underdefined}) { + if ( ! $args->{_parent_info}{underdefined} and ! $args->{_parent_info}{rev_rel_is_optional} ) { for my $col ( values %{$args->{_parent_info}{rel_condition} || {}} ) { next if exists $my_cols->{$col}; $my_cols->{$col} = { via_collapse => $args->{_parent_info}{collapse_on_idcols} }; @@ -228,7 +239,6 @@ sub _resolve_collapse { if $args->{_parent_info}{collapser_reusable}; } - # Still dont know how to collapse - try to resolve based on our columns (plus already inserted FK bridges) if ( ! $collapse_map->{-identifying_columns} @@ -381,8 +391,10 @@ sub _resolve_collapse { # If we got that far - we are collapsable - GREAT! Now go down all children # a second time, and fill in the rest - $collapse_map->{-is_optional} = 1 if $args->{_parent_info}{is_optional}; - + $collapse_map->{-identifying_columns} = [ __unique_numlist( + @{ $args->{_parent_info}{collapse_on_idcols}||[] }, + @{ $collapse_map->{-identifying_columns} }, + )]; my @id_sets; for my $rel (sort keys %$relinfo) { @@ -396,7 +408,14 @@ sub _resolve_collapse { rel_condition => $relinfo->{$rel}{fk_map}, - is_optional => $collapse_map->{-is_optional}, + is_optional => ! $relinfo->{$rel}{is_inner}, + + # if there is at least one *inner* reverse relationship which is HASH-based (equality only) + # we can safely assume that the child can not exist without us + rev_rel_is_optional => ( first + { ref $_->{cond} eq 'HASH' and ($_->{attrs}{join_type}||'') !~ /^left/i } + values %{ $self->reverse_relationship_info($rel) }, + ) ? 0 : 1, # if this is a 1:1 our own collapser can be used as a collapse-map # (regardless of left or not)