@@ -58,6 +58,10 @@ def include_data(value = true)
58
58
:nil
59
59
end
60
60
61
+ def foreign_key_on
62
+ :related
63
+ end
64
+
61
65
# @param serializer [ActiveModel::Serializer]
62
66
# @yield [ActiveModel::Serializer]
63
67
# @return [:nil, associated resource or resource collection]
@@ -90,7 +94,7 @@ def value(serializer)
90
94
# Build association. This method is used internally to
91
95
# build serializer's association by its reflection.
92
96
#
93
- # @param [Serializer] subject is a parent serializer for given association
97
+ # @param [Serializer] parent_serializer is a parent serializer for given association
94
98
# @param [Hash{Symbol => Object}] parent_serializer_options
95
99
#
96
100
# @example
@@ -108,26 +112,30 @@ def value(serializer)
108
112
#
109
113
# @api private
110
114
#
111
- def build_association ( subject , parent_serializer_options )
112
- association_value = value ( subject )
115
+ def build_association ( parent_serializer , parent_serializer_options )
116
+ # association_value = value(parent_serializer )
113
117
reflection_options = options . dup
114
- serializer_class = subject . class . serializer_for ( association_value , reflection_options )
118
+ # model_class = class_name.constantize
119
+ # serializer_class = parent_serializer.class.get_serializer_for(model_class)
120
+
115
121
reflection_options [ :include_data ] = @_include_data
122
+ reflection_options [ :parent_serializer ] = parent_serializer
123
+ reflection_options [ :parent_serializer_options ] = parent_serializer_options
116
124
117
- if serializer_class
118
- begin
119
- serializer = serializer_class . new (
120
- association_value ,
121
- serializer_options ( subject , parent_serializer_options , reflection_options )
122
- )
123
- rescue ActiveModel ::Serializer ::CollectionSerializer ::NoSerializerError
124
- reflection_options [ :virtual_value ] = association_value . try ( :as_json ) || association_value
125
- end
126
- elsif !association_value . nil? && !association_value . instance_of? ( Object )
127
- reflection_options [ :virtual_value ] = association_value
128
- end
125
+ # if serializer_class
126
+ # begin
127
+ # serializer = serializer_class.new(
128
+ # association_value,
129
+ # serializer_options(parent_serializer , parent_serializer_options, reflection_options)
130
+ # )
131
+ # rescue ActiveModel::Serializer::CollectionSerializer::NoSerializerError
132
+ # reflection_options[:virtual_value] = association_value.try(:as_json) || association_value
133
+ # end
134
+ # elsif !association_value.nil? && !association_value.instance_of?(Object)
135
+ # reflection_options[:virtual_value] = association_value
136
+ # end
129
137
130
- Association . new ( name , serializer , reflection_options , @_links , @_meta )
138
+ Association . new ( name , self , reflection_options , @_links , @_meta )
131
139
end
132
140
133
141
protected
@@ -136,12 +144,12 @@ def build_association(subject, parent_serializer_options)
136
144
137
145
private
138
146
139
- def serializer_options ( subject , parent_serializer_options , reflection_options )
147
+ def serializer_options ( parent_serializer , parent_serializer_options , reflection_options )
140
148
serializer = reflection_options . fetch ( :serializer , nil )
141
149
142
150
serializer_options = parent_serializer_options . except ( :serializer )
143
151
serializer_options [ :serializer ] = serializer if serializer
144
- serializer_options [ :serializer_context_class ] = subject . class
152
+ serializer_options [ :serializer_context_class ] = parent_serializer . class
145
153
serializer_options
146
154
end
147
155
end
0 commit comments