Fix container_date sort with non-unique contents user/jeff/container_date_sort
authorJeff Godin <jgodin@tadl.org>
Thu, 22 May 2014 20:36:48 +0000 (16:36 -0400)
committerJeff Godin <jgodin@tadl.org>
Thu, 22 May 2014 20:36:48 +0000 (16:36 -0400)
It is possible for a bre container to have multiple items pointing
to the same bib. In these cases, a container_date sort attempt would
fail with:

ERROR:  more than one row returned by a subquery used as an
expression

This fix considers only a single date, the most recent time a given
bib was added to the container.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 788dc29..07cae51 100644 (file)
@@ -822,7 +822,7 @@ sub toSQL {
     } elseif ($sort_filter eq 'container_date' && @{$$flat_plan{container_list}}) {
         # Just the first container for now
         my $container_id = $self->QueryParser->quote_value(@{$$flat_plan{container_list}}[0]);
-        $rank = "FIRST((SELECT create_time FROM container.biblio_record_entry_bucket_item cbrebi WHERE cbrebi.target_biblio_record_entry = m.source AND cbrebi.bucket = " . $container_id . "))";
+        $rank = "FIRST((SELECT create_time FROM container.biblio_record_entry_bucket_item cbrebi WHERE cbrebi.target_biblio_record_entry = m.source AND cbrebi.bucket = " . $container_id . " ORDER BY create_time DESC LIMIT 1))";
     } else {
         # default to rel ranking
         $rank = $rel;