don't overwrite already set response data when return_object is enabled
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API.pm
index bfdfd76..058e790 100644 (file)
@@ -63,7 +63,8 @@ __PACKAGE__->config();
       ],
       ordered_by       => ['age'],
       search_exposes   => ['age', 'nickname', { cds => ['title', 'year'] }],
-      data_root        => 'data',
+      data_root        => 'list',
+      item_root        => 'data',
       use_json_boolean => 1,
       return_object    => 1,
       );
@@ -963,7 +964,9 @@ sub end : Private {
     if ( $c->res->status == 200 ) {
         $c->stash->{ $self->stash_key }->{success} =
             $self->use_json_boolean ? JSON::true : 'true';
-        if ( $self->return_object && $c->req->has_objects ) {
+        if ( $self->return_object
+            && $c->req->has_objects
+            && ! exists $c->stash->{ $self->stash_key }->{ $self->data_root } ) {
             my $returned_objects = [];
             push( @$returned_objects, $self->each_object_inflate( $c, $_ ) )
                 for map { $_->[0] } $c->req->all_objects;
@@ -1140,11 +1143,17 @@ Controls where in stash request_data should be stored, and defaults to 'response
 
 =head3 data_root
 
-By default, the response data is serialized into
+By default, the response data of multiple item actions is serialized into
 $c->stash->{$self->stash_key}->{$self->data_root} and data_root defaults to
 'list' to preserve backwards compatibility. This is now configuable to meet
 the needs of the consuming client.
 
+=head3 item_root
+
+By default, the response data of single item actions is serialized into
+$c->stash->{$self->stash_key}->{$self->item_root} and item_root default to
+'data'.
+
 =head3 use_json_boolean
 
 By default, the response success status is set to a string value of "true" or
@@ -1324,12 +1333,15 @@ The validator is set in "loose" mode meaning only one path is required to match.
 For more information, please see L<Data::DPath::Validator> and more specifically
 L<Catalyst::Controller::DBIC::API::Validator>.
 
-Since 2.00100:
+Since 2.001:
 Transactions are used. The stash is put aside in favor of roles applied to the
 request object with additional accessors.
 Error handling is now much more consistent with most errors immediately detaching.
 The internals are much easier to read and understand with lots more documentation.
 
+Since 2.006:
+The SQL::Abstract -and, -not and -or operators are supported.
+
 =cut
 
 1;