Skip to content

Commit 2364a0a

Browse files
committed
Adds section on new attribute delegation
1 parent 225c3e3 commit 2364a0a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ class ContactResource < JSONAPI::Resource
193193
end
194194
```
195195

196+
##### Attribute Delegation
197+
198+
Normally resource attributes map to an attribute on the model of the same name. Using the `delegate` option allows a resource
199+
attribute to map to a differently named model attribute. For example:
200+
201+
```ruby
202+
class ContactResource < JSONAPI::Resource
203+
attribute :name_first, delegate: :first_name
204+
attribute :name_last, delegate: :last_name
205+
end
206+
```
207+
196208
##### Fetchable Attributes
197209

198210
By default all attributes are assumed to be fetchable. The list of fetchable attributes can be filtered by overriding

0 commit comments

Comments
 (0)