File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed
lib/active_model_serializers Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change 42
42
43
43
The default serializer would be ` MyModelSerializer ` .
44
44
45
+ * IMPORTANT* : There is a surprising behavior (bug) in the current implementation of ActiveModelSerializers::Model that
46
+ prevents an accessor from modifying attributes on the instance. The fix for this bug
47
+ is a breaking change, so we have made an opt-in configuration.
48
+
49
+ New applications should set:
50
+
51
+ ``` ruby
52
+ ActiveModelSerializers ::Model .derive_attributes_from_names_and_fix_accessors
53
+ ```
54
+
55
+ Existing applications can use the fix * and* avoid breaking changes
56
+ by making a superclass for new models. For example:
57
+
58
+ ``` ruby
59
+ class SerializablePoro < ActiveModelSerializers ::Model
60
+ derive_attributes_from_names_and_fix_accessors
61
+ end
62
+ ```
63
+
64
+ So that ` MyModel ` above would inherit from ` SerializablePoro ` .
65
+
66
+ ` derive_attributes_from_names_and_fix_accessors ` prepends the ` DeriveAttributesFromNamesAndFixAccessors `
67
+ module and does the following:
68
+
69
+ - ` id ` will * always* be in the attributes. (This is until we separate out the caching requirement for POROs.)
70
+ - Overwrites the ` attributes ` method to that it only returns declared attributes.
71
+ ` attributes ` will now be a frozen hash with indifferent access.
72
+
45
73
For more information, see [ README: What does a 'serializable resource' look like?] ( ../../README.md#what-does-a-serializable-resource-look-like ) .
Original file line number Diff line number Diff line change @@ -56,14 +56,6 @@ def self.included(base)
56
56
base . attributes :id
57
57
end
58
58
59
- # Override the initialize method so that attributes aren't processed.
60
- #
61
- # @param attributes [Hash]
62
- def initialize ( attributes = { } )
63
- @errors = ActiveModel ::Errors . new ( self )
64
- super
65
- end
66
-
67
59
# Override the +attributes+ method so that the hash is derived from +attribute_names+.
68
60
#
69
61
# The the fields in +attribute_names+ determines the returned hash.
You can’t perform that action at this time.
0 commit comments