| 1 | package App::Netdisco::DB::Result; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'DBIx::Class::Core'; | ||
| 7 | |||
| 8 | BEGIN { | ||
| 9 | no warnings 'redefine'; | ||
| 10 | __PACKAGE__->load_components(qw{Helper::Row::ToJSON}); | ||
| 11 | |||
| 12 | # this replacement will avoid the issue of relation names which override | ||
| 13 | # field names, causing TO_JSON to return object instances, breaking to_json | ||
| 14 | *DBIx::Class::Helper::Row::ToJSON::TO_JSON = sub { | ||
| 15 | my $self = shift; | ||
| 16 | my $columns_info = $self->columns_info($self->serializable_columns); | ||
| 17 | my $columns_data = { $self->get_columns }; | ||
| 18 | return { | ||
| 19 | map +($_ => $columns_data->{$_}), keys %$columns_info | ||
| 20 | }; | ||
| 21 | }; | ||
| 22 | } | ||
| 23 | |||
| 24 | # for DBIx::Class::Helper::Row::ToJSON | ||
| 25 | # to allow text columns to be included in results | ||
| 26 | |||
| 27 | sub unserializable_data_types { | ||
| 28 | return { | ||
| 29 | blob => 1, | ||
| 30 | ntext => 1, | ||
| 31 | }; | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; |