diff --git a/Changes b/Changes index f025c802..ec68ab47 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ * #740 more robust log rotation * #762 wide character error on deploy with local oui.txt + * error when using API /api/v1/object/device/ip/port_vlans 2.047002 - 2020-12-30 diff --git a/lib/App/Netdisco/DB/Result.pm b/lib/App/Netdisco/DB/Result.pm index 042e9fb9..19ae76be 100644 --- a/lib/App/Netdisco/DB/Result.pm +++ b/lib/App/Netdisco/DB/Result.pm @@ -5,7 +5,21 @@ use warnings; use base 'DBIx::Class::Core'; -__PACKAGE__->load_components(qw{Helper::Row::ToJSON}); +BEGIN { + no warnings 'redefine'; + __PACKAGE__->load_components(qw{Helper::Row::ToJSON}); + + # this replacement will avoid the issue of relation names which override + # field names, causing TO_JSON to return object instances, breaking to_json + *DBIx::Class::Helper::Row::ToJSON::TO_JSON = sub { + my $self = shift; + my $columns_info = $self->columns_info($self->serializable_columns); + my $columns_data = { $self->get_columns }; + return { + map +($_ => $columns_data->{$_}), keys %$columns_info + }; + }; +} # for DBIx::Class::Helper::Row::ToJSON # to allow text columns to be included in results