ToJSON: serialize boolean_columns to JSON boolean

This commit is contained in:
Graham Christensen 2021-04-26 16:00:57 -07:00 committed by Cole Helbling
parent 683b8c41c1
commit 4aea02e1e1
No known key found for this signature in database
GPG key ID: B37E0F2371016A4C

View file

@ -5,6 +5,7 @@ use strict;
use warnings; use warnings;
use base 'DBIx::Class'; use base 'DBIx::Class';
use JSON;
sub TO_JSON { sub TO_JSON {
my $self = shift; my $self = shift;
@ -17,6 +18,10 @@ sub TO_JSON {
$json{$column} = $self->get_column($column); $json{$column} = $self->get_column($column);
} }
foreach my $column (@{$hint->{boolean_columns}}) {
$json{$column} = $self->get_column($column) ? JSON::true : JSON::false;
}
foreach my $relname (keys %{$hint->{relations}}) { foreach my $relname (keys %{$hint->{relations}}) {
my $key = $hint->{relations}->{$relname}; my $key = $hint->{relations}->{$relname};
$json{$relname} = [ map { $_->$key } $self->$relname ]; $json{$relname} = [ map { $_->$key } $self->$relname ];