@@ -139,7 +139,9 @@ def self.expose(*args, &block)
139
139
140
140
args . each do |attribute |
141
141
unless @nested_attributes . empty?
142
+ orig_attribute = attribute . to_sym
142
143
attribute = "#{ @nested_attributes . last } __#{ attribute } "
144
+ nested_attribute_names_hash [ attribute . to_sym ] = orig_attribute
143
145
options [ :nested ] = true
144
146
nested_exposures_hash [ @nested_attributes . last . to_sym ] ||= { }
145
147
nested_exposures_hash [ @nested_attributes . last . to_sym ] [ attribute . to_sym ] = options
@@ -187,12 +189,29 @@ def self.exposures
187
189
end
188
190
189
191
class << self
192
+ attr_accessor :_nested_attribute_names_hash
190
193
attr_accessor :_nested_exposures_hash
191
194
195
+ def nested_attribute_names_hash
196
+ self . _nested_attribute_names_hash ||= { }
197
+ end
198
+
192
199
def nested_exposures_hash
193
200
self . _nested_exposures_hash ||= { }
194
201
end
195
202
203
+ def nested_attribute_names
204
+ return @nested_attribute_names unless @nested_attribute_names . nil?
205
+
206
+ @nested_attribute_names = { } . merge ( nested_attribute_names_hash )
207
+
208
+ if superclass . respond_to? :nested_attribute_names
209
+ @nested_attribute_names = superclass . nested_attribute_names . deep_merge ( @nested_attribute_names )
210
+ end
211
+
212
+ @nested_attribute_names
213
+ end
214
+
196
215
def nested_exposures
197
216
return @nested_exposures unless @nested_exposures . nil?
198
217
@@ -408,7 +427,8 @@ def to_xml(options = {})
408
427
protected
409
428
410
429
def self . name_for ( attribute )
411
- attribute . to_s . split ( '__' ) . last . to_sym
430
+ attribute = attribute . to_sym
431
+ nested_attribute_names [ attribute ] || attribute
412
432
end
413
433
414
434
def self . key_for ( attribute )
0 commit comments