Skip to content

Commit 226cbc4

Browse files
committed
Unsuffixed association keys doc
1 parent 4ac07de commit 226cbc4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ end
236236
BlogSerializer.new(object, key_format: :lower_camel)
237237
```
238238

239+
## Changing the default association key type
240+
241+
You can specify that serializers use unsuffixed names as association keys by default.
242+
243+
`````ruby
244+
ActiveModel::Serializer.setup do |config|
245+
config.default_key_type = :name
246+
end
247+
````
248+
249+
This will build association keys like `comments` or `author` instead of `comment_ids` or `author_id`.
250+
239251
## Getting the old version
240252

241253
If you find that your project is already relying on the old rails to_json

0 commit comments

Comments
 (0)