forked from lix-project/hydra
ToJSON: serialize boolean_columns to JSON boolean
This commit is contained in:
parent
683b8c41c1
commit
4aea02e1e1
|
@ -5,6 +5,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use base 'DBIx::Class';
|
||||
use JSON;
|
||||
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
|
@ -17,6 +18,10 @@ sub TO_JSON {
|
|||
$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}}) {
|
||||
my $key = $hint->{relations}->{$relname};
|
||||
$json{$relname} = [ map { $_->$key } $self->$relname ];
|
||||
|
|
Loading…
Reference in a new issue