my $piece;
while ($piece = shift @$path) {
- $logger->debug("_flattened_search_single_flesh_wad() dealing with $piece");
my $link = _fm_link_from_class($class, $piece);
if ($link) {
$flesh_fields->{$hint} ||= [];
my $alias; # yes, we need it out at this scope.
while ($piece = shift @$path) {
- $logger->debug("_flattened_search_single_join_clause() dealing with $piece");
-
my $link = _fm_link_from_class($class, $piece);
if ($link) {
$hint = $link->{class};
# $new->{flesh_fields}{$key}, treating the arrays as sets.
my %hash = map { $_ => 1 } (
- @{ $old->{flesh_fields}{$key} },
+ @{ $old->{flesh_fields}{$key} },
@{ $new->{flesh_fields}{$key} }
);
$old->{flesh_fields}{$key} = [ keys(%hash) ];
return $o->{$table}{$column};
} else { # field must be on core class
- $o->{$column} = $o->{$key};
- delete $o->{$key};
+ if ($column ne $key) {
+ $o->{$column} = $o->{$key};
+ delete $o->{$key};
+ }
return $o->{$column};
}
} else {
# intended to avoid trying to map things like "between" in
# constructs like:
# {"somecolumn": {"between": [1,10]}}
- # and to that extend, it succeeds.
+ # and to that extent, it works.
if (not $state->{in_expr} and $key =~ /^[a-z]/) {
$state->{in_expr} = 1;
- my $deeper = _flattened_search_expand_filter_column(
- $o, $key, $map
- );
-
_flattened_search_recursively_apply_map_to_filter(
- $deeper, $map, $state
+ _flattened_search_expand_filter_column($o, $key, $map),
+ $map, $state
);
$state->{in_expr} = 0;
return $jffolo unless $slo->{sort};
# The slo has a special format for 'sort' that gives callers what they
- # need, but isn't as flexible as json_query's order_by.
+ # need, but isn't as flexible as json_query's 'order_by'.
#
# "sort": [{"column1": "asc"}, {"column2": "desc"}]
- # or optionally,
+ # or
+ # "sort": ["column1", {"column2": "desc"}]
+ # or
# "sort": {"onlycolumn": "asc"}
+ # or
+ # "sort": "onlycolumn"
$jffolo->{order_by} = [];
# coerce from optional simpler format (see comment blob above)
- $slo->{sort} = [ $slo->{sort} ] if ref $slo->{sort} eq "HASH";
+ $slo->{sort} = [ $slo->{sort} ] unless ref $slo->{sort} eq "ARRAY";
foreach my $exp (@{ $slo->{sort} }) {
- # XXX By assuming that each sort expression is a single key/value pair,
- # we preclude the ability to use transforms and the like for now.
+ $exp = { $exp => "asc" } unless ref $exp;
+
+ # XXX By assuming that each sort expression is (at most) a single
+ # key/value pair, we preclude the ability to use transforms and the
+ # like for now.
my ($key) = keys(%$exp);
return $jffolo;
}
+# Given a map and a fieldmapper object, return a flat representation as
+# specified by the map's display fields
sub process_result {
my ($map, $fmobj) = @_;
+ if (not ref $fmobj) {
+ throw OpenSRF::EX::ERROR(
+ "process_result() was passed an inappropriate second argument"
+ );
+ }
+
my $flatrow = {};
while (my ($key, $mapping) = each %$map) {
my $obj = $fmobj;
while (my $step = shift @path) {
$obj = $obj->$step;
+ last unless ref $obj;
}
- $flatrow->{$key} = $obj->$field;
+ $flatrow->{$key} = ref $obj ? $obj->$field : undef;
}
return $flatrow;