mirror of
https://github.com/ditkrg/jsonapi-deserializable.git
synced 2026-01-22 13:56:50 +00:00
Updated README
This commit is contained in:
parent
887c506fd2
commit
726d6828db
51
README.md
51
README.md
@ -2,6 +2,57 @@
|
|||||||
Ruby gem for deserializing [JSON API](http://jsonapi.org) payloads into custom
|
Ruby gem for deserializing [JSON API](http://jsonapi.org) payloads into custom
|
||||||
hashes.
|
hashes.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
#### Support for included documents
|
||||||
|
|
||||||
|
To insert the included documents to ``has_one`` and ``has_many`` relation ship, use the ``with_included: true`` option to the relationship:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class DeserializableBook < JSONAPI::Deserializable::Resource
|
||||||
|
id
|
||||||
|
type
|
||||||
|
attributes :id,
|
||||||
|
:title
|
||||||
|
|
||||||
|
has_one :author, with_included: true
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
To use a custom deserializer for the included relationship, use the ``deserializer`` option:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class DeserializableBook < JSONAPI::Deserializable::Resource
|
||||||
|
id
|
||||||
|
type
|
||||||
|
attributes :id,
|
||||||
|
:title
|
||||||
|
|
||||||
|
has_one :author, with_included: true, deserializer: DeserialzableAuthor
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
If the property name is different than the included object type, pass the ``type`` option:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class DeserializableBook < JSONAPI::Deserializable::Resource
|
||||||
|
id
|
||||||
|
type
|
||||||
|
attributes :id,
|
||||||
|
:title
|
||||||
|
|
||||||
|
has_one :author, with_included: true, deserializer: DeserializablePerson, type: 'people'
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
[](https://badge.fury.io/rb/jsonapi-deserializable)
|
[](https://badge.fury.io/rb/jsonapi-deserializable)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user