Restore ability to handle underdefined root (t/prefetch/incomplete.t)
authorPeter Rabbitson <ribasushi@cpan.org>
Thu, 3 Jan 2013 03:01:36 +0000 (04:01 +0100)
committerPeter Rabbitson <ribasushi@cpan.org>
Thu, 14 Feb 2013 05:34:50 +0000 (06:34 +0100)
commitfcf32d04540e2c67625641b0bc004111a7d90252
tree37e3ccc6ad52b00b52341eac266b21b54d3f7ac2
parent574dd7c9e960fd2fa6ad083454776adf3cd967e9
Restore ability to handle underdefined root (t/prefetch/incomplete.t)

In addition make things work when multiple has_many-inheriting branches
are present on the root. This squeezes in the last thing I could think
of into the row_parser maker, and allows to *properly* collapse stuff
like this:

$rs = $schema->resultset ('CD')->search ({}, {
  join => [ 'tracks', { single_track => { cd => { artist => { cds => 'tracks' } } } }  ],
  collapse => 1,
  columns => [
    { 'single_track.trackid'                    => 'single_track.trackid' },  # definitive link to root from 1:1:1:1:M:M chain
    { 'year'                                    => 'me.year' },               # non-unique
    { 'tracks.cd'                               => 'tracks.cd' },             # \ together both uniqueness for second multirel
    { 'tracks.title'                            => 'tracks.title' },          # / and definitive link back to root
    { 'single_track.cd.artist.cds.cdid'         => 'cds.cdid' },              # to give uniquiness to ...tracks.title below
    { 'single_track.cd.artist.cds.year'         => 'cds.year' },              # non-unique
    { 'single_track.cd.artist.artistid'         => 'artist.artistid' },       # uniqufies entire parental chain
    { 'single_track.cd.artist.cds.genreid'      => 'cds.genreid' },           # nullable
    { 'single_track.cd.artist.cds.tracks.title' => 'tracks_2.title' },        # unique when combined with ...cds.cdid above
  ],
  order_by => \ 'RANDOM()'
});

Which DBIC sees like this ( produced by `prove -l t/prefetch/manual.t -v` ):

 sngl_tr.trackid #        me.year #       tracks.cd #    tracks.title #        cds.cdid #        cds.year # artist.artistid #     cds.genreid #  tracks_2.title
---------------------------------------------------------------------------------------------------------------------------------------------------------------
               6 #           1978 #               3 #              e2 #               1 #            1981 #               1 #               1 #              m3
            NULL #           1977 #            NULL #            NULL #            NULL #            NULL #            NULL #            NULL #            NULL
               6 #           1978 #               3 #              e3 #               5 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e1 #               1 #            1981 #               1 #               1 #              m1
               6 #           1978 #               3 #              e2 #               3 #            1978 #               1 #               1 #              e1
            NULL #           1981 #               1 #              m1 #            NULL #            NULL #            NULL #            NULL #            NULL
               6 #           1978 #               3 #              e2 #               1 #            1981 #               1 #               1 #              m1
               6 #           1978 #               3 #              e3 #               3 #            1978 #               1 #               1 #              e3
               6 #           1978 #               3 #              e3 #               2 #            1976 #               1 #            NULL #              o2
               6 #           1978 #               3 #              e2 #               6 #            1977 #               1 #            NULL #            NULL
            NULL #           1981 #               1 #              m3 #            NULL #            NULL #            NULL #            NULL #            NULL
               6 #           1978 #               3 #              e3 #               1 #            1981 #               1 #               1 #              m1
               6 #           1978 #               3 #              e1 #               2 #            1976 #               1 #            NULL #              o2
               6 #           1978 #               3 #              e3 #               1 #            1981 #               1 #               1 #              m3
               6 #           1978 #               3 #              e2 #               3 #            1978 #               1 #               1 #              e2
               6 #           1978 #               3 #              e2 #               4 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e1 #               6 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e2 #               5 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e1 #               3 #            1978 #               1 #               1 #              e2
               6 #           1978 #               3 #              e1 #               3 #            1978 #               1 #               1 #              e1
            NULL #           1976 #               2 #              o1 #            NULL #            NULL #            NULL #            NULL #            NULL
            NULL #           1976 #               2 #              o2 #            NULL #            NULL #            NULL #            NULL #            NULL
               6 #           1978 #               3 #              e1 #               1 #            1981 #               1 #               1 #              m2
               6 #           1978 #               3 #              e1 #               5 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e2 #               2 #            1976 #               1 #            NULL #              o1
               6 #           1978 #               3 #              e2 #               1 #            1981 #               1 #               1 #              m2
               6 #           1978 #               3 #              e1 #               1 #            1981 #               1 #               1 #              m4
               6 #           1978 #               3 #              e3 #               1 #            1981 #               1 #               1 #              m2
               6 #           1978 #               3 #              e2 #               2 #            1976 #               1 #            NULL #              o2
               6 #           1978 #               3 #              e3 #               3 #            1978 #               1 #               1 #              e1
               6 #           1978 #               3 #              e3 #               1 #            1981 #               1 #               1 #              m4
               6 #           1978 #               3 #              e1 #               3 #            1978 #               1 #               1 #              e3
            NULL #           1977 #            NULL #            NULL #            NULL #            NULL #            NULL #            NULL #            NULL
               6 #           1978 #               3 #              e1 #               1 #            1981 #               1 #               1 #              m3
               6 #           1978 #               3 #              e3 #               2 #            1976 #               1 #            NULL #              o1
               6 #           1978 #               3 #              e1 #               2 #            1976 #               1 #            NULL #              o1
               6 #           1978 #               3 #              e2 #               1 #            1981 #               1 #               1 #              m4
               6 #           1978 #               3 #              e3 #               3 #            1978 #               1 #               1 #              e2
            NULL #           1977 #            NULL #            NULL #            NULL #            NULL #            NULL #            NULL #            NULL
            NULL #           1981 #               1 #              m2 #            NULL #            NULL #            NULL #            NULL #            NULL
               6 #           1978 #               3 #              e3 #               6 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e2 #               3 #            1978 #               1 #               1 #              e3
               6 #           1978 #               3 #              e3 #               4 #            1977 #               1 #            NULL #            NULL
               6 #           1978 #               3 #              e1 #               4 #            1977 #               1 #            NULL #            NULL
            NULL #           1981 #               1 #              m4 #            NULL #            NULL #            NULL #            NULL #            NULL
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/ResultSource/RowParser.pm
t/prefetch/incomplete.t
t/prefetch/manual.t
t/resultset/rowparser_internals.t