mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #630 from sachse/readme-fix
README: Change :embed_key to :key
This commit is contained in:
commit
e41eedd4dd
@ -524,15 +524,15 @@ Now, any associations will be supplied as an Array of IDs:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You may also choose to embed the IDs by the association's name underneath an
|
You may also choose to embed the IDs by the association's name underneath a
|
||||||
`embed_key` for the resource. For example, say we want to change `comment_ids`
|
`key` for the resource. For example, say we want to change `comment_ids`
|
||||||
to `comments` underneath a `links` key:
|
to `comments` underneath a `links` key:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class PostSerializer < ActiveModel::Serializer
|
class PostSerializer < ActiveModel::Serializer
|
||||||
attributes :id, :title, :body
|
attributes :id, :title, :body
|
||||||
|
|
||||||
has_many :comments, embed: :ids, embed_namespace: :links
|
has_many :comments, embed: :ids, key: :comments, embed_namespace: :links
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -694,7 +694,7 @@ class PostSerializer < ActiveModel::Serializer
|
|||||||
embed :ids, include: true
|
embed :ids, include: true
|
||||||
|
|
||||||
attributes :id, :title, :body
|
attributes :id, :title, :body
|
||||||
has_many :comments, embed_key: :external_id
|
has_many :comments, key: :external_id
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user