Commit Graph

1101 Commits

Author SHA1 Message Date
Alexandre de Oliveira
e47231cdc8 Support overriding association methods
You can override associations to define custom scope on them.
2015-01-29 16:52:18 -02:00
Guillermo Iguaran
652493848a Merge pull request #774 from nhocki/fix_nested_linked_objects
Fix nested include attributes
2015-01-13 17:01:23 -05:00
Nicolás Hock Isaza
1d7d9fd6aa Fix nested include attributes
When the requests asked for a nested attribute in the `include` and it's
missing or empty, don't break because the type of the object can't be
determined.

If the request is for a collection and none of the elements has the
attribute, it will not be added to the `linked` key, similar to what
happens with simple includes.
2015-01-13 14:49:58 -05:00
Guillermo Iguaran
22202a115a Lets keep the assert_equal without parens for consistency. 2015-01-11 16:21:20 -05:00
Guillermo Iguaran
7085afe714 Merge pull request #771 from sweatypitts/master
Make linked resource type names consistent with root names
2015-01-11 16:20:15 -05:00
Robbie Pitts
b626ec8f14 Spec for linked resource type name demodulization 2015-01-11 16:10:02 -05:00
Robbie Pitts
90023b1af7 Make linked resource type names consistent with root names 2015-01-11 14:24:01 -05:00
Alexandre de Oliveira
6eb75af96b Merge pull request #696 from ggordon/explicit_serializer
Explicitly set serializer for associations
2015-01-06 09:57:07 -02:00
Alexandre de Oliveira
87f817943a Merge pull request #700 from arenoir/sparse_fieldsets
sparse fieldsets
2015-01-06 09:38:51 -02:00
Guillermo Iguaran
3a60633545 Merge pull request #768 from rails-api/adds-meta
Adds support for meta attribute
2015-01-05 00:10:09 -05:00
Alexandre de Oliveira
bd27da1b76 Adds support for meta attribute
Currently, 0.10.0.pre doesn't support `meta` option in `render`. This
way, there's no way to support features such as pagination. `0.9` had
this feature in place.

This adds support for it, as well as fixes small things in README.md.

This won't support `meta` in array responses because arrays don't have
keys, obviously. Also, the response should have a `root` key, otherwise
no `meta` will be included.

In some cases, for example using JsonApi, ArraySerializer will result in
a response with a `root`. In that case, `meta` will be included.
2015-01-05 02:56:33 -02:00
Steve Klabnik
282de21984 Merge pull request #753 from tricknotes/ruby-22
Test against Ruby 2.2 on Travis CI
2014-12-09 23:52:01 -05:00
Ryunosuke SATO
b3dc3f4dbe Test against Ruby 2.2 on Travis CI 2014-12-10 02:40:47 +09:00
Ryunosuke SATO
2135256004 Test against latest Ruby 2.1.x on Travis CI 2014-12-10 02:40:45 +09:00
Steve Klabnik
c67da11b96 Merge pull request #745 from jockee/patch-1
Missing a word
2014-12-04 17:20:33 +01:00
Joakim Ekström
9768da7a70 Missing a word 2014-12-04 17:05:10 +01:00
Steve Klabnik
8bbf6b8c8b Merge pull request #707 from jherdman/patch-1
A Friendly Note on Which AMS Version to Use
2014-11-20 10:27:19 -05:00
James Herdman
faa6f906d6 A Friendly Note on Which AMS Version to Use
Per the discussion in #702, I figured it might be nice to note which
version of AMS is recommended to be used in new projects.
2014-11-20 10:20:04 -05:00
Alexandre de Oliveira
a933d44673 Merge pull request #730 from rails-api/fixes-nested-has-many-links
Fixes nested has_many links in JSONAPI
2014-11-17 11:30:20 -02:00
Aaron Renoir
2ed52f96a6 merge upstream update fieldset 2014-11-13 17:45:47 -08:00
Alexandre de Oliveira
2f5626d616 Fixes nested has_many links in JSONAPI
When linked resource had has_many links, all of them would use the
association from the first resource, causing all of the items to build
`links` with the same associations.

This fixes it by iterating over the serializers, not just the
attributes array.
2014-11-13 16:38:47 -02:00
Alexandre de Oliveira
c53f1da18e Merge pull request #718 from ggordon/adapter_override
Allow overriding the adapter with render option
2014-11-13 13:59:12 -02:00
Gary Gordon
5560b49098 Allow overriding the adapter with render option
Make it easy to use multiple adapters in an app.

use "adapter: false" to not use ams

make a test override config.adapter
2014-11-13 10:23:19 -05:00
Gary Gordon
9f9715801a Explicitly set serializer for associations
Document specifying serializer for assocaition
2014-11-13 10:17:59 -05:00
Alexandre de Oliveira
08fbba9087 Merge pull request #720 from ggordon/attribute_with_key
Rename attribute with :key (0.8.x compatibility)
2014-11-13 11:38:06 -02:00
Gary Gordon
08716d20c9 Rename attribute with :key (0.8.x compatibility) 2014-11-13 08:03:22 -05:00
Alexandre de Oliveira
ac37570bff Merge pull request #728 from rails-api/linked-resources-use-type-as-key
Use type as key for linked resources
2014-11-13 10:53:59 -02:00
Alexandre de Oliveira
90b88da70a Fixes rbx gems bundling on TravisCI
Fixes https://github.com/travis-ci/travis-ci/issues/2821
2014-11-13 10:35:41 -02:00
Steve Klabnik
7dd2ee8690 Merge pull request #729 from joshk/patch-2
Use the new beta build env on Travis
2014-11-12 18:18:04 -05:00
Josh Kalderimis
9064955499 Use the new beta build env on Travis
also remove the custom bundle install line as Travis does that by default
2014-11-12 14:34:34 -08:00
Alexandre de Oliveira
4af02021ac Merge pull request #703 from ggordon/specify_serializer_from_controller
Support serializer and each_serializer options in renderer
2014-11-12 20:09:51 -02:00
Alexandre de Oliveira
7333f20285 Use type as key for linked resources
If type is `author` but the association is called `writer`, the linked
resource key should be called `authors`, e.g

    {
      ...
      linked: {
        authors: [{
          ...
        }]
      }
      ...
    }
2014-11-12 20:03:25 -02:00
Alexandre de Oliveira
5038147c4c Merge pull request #727 from rails-api/include-links-in-linked-resources
Includes links inside of linked resources
2014-11-12 19:08:50 -02:00
Alexandre de Oliveira
91b3fba509 Includes links inside of linked resources
According to
http://jsonapi.org/format/#document-structure-resource-objects,

> Resource objects have the same internal structure, regardless of
> whether they represent primary or linked resources.

And then
http://jsonapi.org/format/#document-structure-resource-object-attributes,

> There are four reserved keys in resource objects:
>
> "id"
> "type"
> "href"
> "links"

This commits includes `links` inside of linked resources.
2014-11-12 15:44:54 -02:00
Alexandre de Oliveira
7592e838ee Merge pull request #726 from rails-api/json-api-include-with-nested-has-many
Bugfix: include nested has_many associations
2014-11-11 22:51:45 -02:00
Alexandre de Oliveira
971f501e55 Bugfix: include nested has_many association
Currently, doing `include: author.bio` would work correctly, but not for
has_many associations such as `include: author.roles`. This fixes it.

The problem was basically that we were not handling arrays for has_many linked,
as happens for ArraySerializers.
2014-11-11 14:35:00 -02:00
Alexandre de Oliveira
33e8d09ad0 Merge pull request #722 from ggordon/stack_level_too_deep
Fix infinite recursion
2014-11-10 12:31:14 -02:00
Gary Gordon
3925f93df2 Merge pull request #1 from metermd/master
Allow for the implicit use of ArraySerializer when :each_serializer is specified
2014-11-07 10:21:40 -05:00
Gary Gordon
d97b2f5005 Fix infinite recursion
The method for testing whether to include an association was causing
an infinite loop when two models referenced each other.
2014-11-07 10:03:31 -05:00
Mike A. Owens
58b6c4a6b7 Allow for the implicit use of ArraySerializer when :each_serializer is specified. 2014-11-07 09:39:36 -05:00
Aaron Renoir
fc1562c04a add fields to adapter initialize function, pull in master, add tests using includes with fields 2014-11-05 18:10:37 -08:00
Aaron Renoir
c9c58e31e5 merge upstream/master 2014-11-05 16:47:15 -08:00
Gary Gordon
c84430cdad Support serializer and each_serializer in render json 2014-11-05 15:10:14 -05:00
Alexandre de Oliveira
95d122046d Merge pull request #692 from ggordon/linked_for_jsonapi_collection
Include 'linked' member for json-api collections
2014-11-04 21:59:15 -02:00
Carlos Antonio da Silva
8374396b88 Merge pull request #714 from ride/to-json-as-json
Define as_json instead of to_json
2014-11-03 22:00:36 -02:00
Guillermo Iguaran
f5411f045f Define as_json instead of to_json 2014-11-03 17:38:58 -05:00
Gary Gordon
d5bae0c2f0 Include 'linked' member for json-api collections
The options passed to the render are partitioned into adapter options
and serializer options. 'include' and 'root' are sent to the adapter,
not sure what options would go directly to serializer, but leaving this
in until I understand that better.
2014-11-03 17:13:55 -05:00
Alexandre de Oliveira
80ece39dd9 Merge pull request #710 from ride/fix-empty-linked
JSON-API: Don't include linked section if associations are empty
2014-11-02 01:53:37 -02:00
Alexandre de Oliveira
deaf55eeae Merge pull request #711 from rails-api/fixes-rbx-on-travis
Fixes rbx gems bundling on TravisCI
2014-11-02 01:51:14 -02:00
Alexandre de Oliveira
3504c1a5d8 Fixes rbx gems bundling on TravisCI 2014-11-02 01:23:29 -02:00