View | Details | Raw Unified | Return to bug 24528
Collapse All | Expand All

(-)a/Koha/Object.pm (-13 / +20 lines)
Lines 428-448 sub to_api { Link Here
428
428
429
    if ($embeds) {
429
    if ($embeds) {
430
        foreach my $embed ( keys %{$embeds} ) {
430
        foreach my $embed ( keys %{$embeds} ) {
431
            my $curr = $embed;
431
            if ( $embed =~ m/^(?<relation>.*)_count$/
432
            my $next = $embeds->{$curr}->{children};
432
                and $embeds->{$embed}->{is_count} ) {
433
433
434
            my $children = $self->$curr;
434
                my $relation = $+{relation};
435
435
                $json_object->{$embed} = $self->$relation->count;
436
            if ( defined $children and ref($children) eq 'ARRAY' ) {
437
                my @list = map {
438
                    $self->_handle_to_api_child(
439
                        { child => $_, next => $next, curr => $curr } )
440
                } @{$children};
441
                $json_object->{$curr} = \@list;
442
            }
436
            }
443
            else {
437
            else {
444
                $json_object->{$curr} = $self->_handle_to_api_child(
438
                my $curr = $embed;
445
                    { child => $children, next => $next, curr => $curr } );
439
                my $next = $embeds->{$curr}->{children};
440
441
                my $children = $self->$curr;
442
443
                if ( defined $children and ref($children) eq 'ARRAY' ) {
444
                    my @list = map {
445
                        $self->_handle_to_api_child(
446
                            { child => $_, next => $next, curr => $curr } )
447
                    } @{$children};
448
                    $json_object->{$curr} = \@list;
449
                }
450
                else {
451
                    $json_object->{$curr} = $self->_handle_to_api_child(
452
                        { child => $children, next => $next, curr => $curr } );
453
                }
446
            }
454
            }
447
        }
455
        }
448
    }
456
    }
449
- 

Return to bug 24528