scalar data are ids

releases
Yanick Champoux 2023-11-01 15:21:06 -04:00
parent 8639858b60
commit 5dd5e664e9
2 changed files with 13 additions and 0 deletions

View File

@ -85,6 +85,9 @@ sub serialize_data ( $self, $data, $extra_data = {}, $included = undef ) {
return [ map { $self->serialize_data($_,$extra_data, $included) } @$data ] if ref $data eq 'ARRAY';
# it's a scalar? it's the id
return { id => $data, type => $self->type } unless ref $data;
my $s = {
type => $self->type,
id => $self->gen_id($data) };

View File

@ -66,6 +66,16 @@ subtest 'attributes' => sub {
};
subtest 'a single scalar == id', sub {
my $serialized =
Dancer2::Plugin::JsonApi::Registry::Schema->new( type => 'thing' )
->serialize('blah');
is $serialized->{data} => {
type => 'thing',
id => 'blah',
};
};
done_testing();