File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,26 @@ Serialization of the resource `title`
38
38
39
39
### Associations
40
40
41
+ The interface for associations is, generically:
42
+
43
+ > ` association_type(association_name, options, &block) `
44
+
45
+ Where:
46
+
47
+ - ` association_type ` may be ` has_one ` , ` has_many ` , ` belongs_to ` .
48
+ - ` association_name ` is a method name the serializer calls.
49
+ - optional: ` options ` may be:
50
+ - ` key: ` The name used for the serialized association.
51
+ - ` serializer: `
52
+ - ` if: `
53
+ - ` unless: `
54
+ - ` virtual_value: `
55
+ - optional: ` &block ` is a context that returns the association's attributes.
56
+ - prevents ` association_name ` method from being called.
57
+ - return value of block is used as the association value.
58
+ - yields the ` serializer ` to the block.
59
+ - ` include_data false ` prevents the ` data ` key from being rendered in the JSON API relationship.
60
+
41
61
#### ::has_one
42
62
43
63
e.g.
@@ -58,6 +78,14 @@ def cached_blog
58
78
end
59
79
```
60
80
81
+ ``ruby
82
+ has_one : blog , if: : show_blog ?
83
+
84
+ def show_blog?
85
+ scope.admin?
86
+ end
87
+ ```
88
+
61
89
#### ::has_many
62
90
63
91
e.g.
You can’t perform that action at this time.
0 commit comments