@@ -455,6 +455,7 @@ def inherited(subclass)
455
455
subclass . _warned_missing_route = false
456
456
457
457
subclass . _clear_cached_attribute_options
458
+ subclass . _clear_fields_cache
458
459
end
459
460
460
461
def rebuild_relationships ( relationships )
@@ -530,6 +531,7 @@ def attributes(*attrs)
530
531
531
532
def attribute ( attribute_name , options = { } )
532
533
_clear_cached_attribute_options
534
+ _clear_fields_cache
533
535
534
536
attr = attribute_name . to_sym
535
537
@@ -697,7 +699,7 @@ def sortable_field?(key, context = nil)
697
699
end
698
700
699
701
def fields
700
- _relationships . keys | _attributes . keys
702
+ @_fields_cache ||= _relationships . keys | _attributes . keys
701
703
end
702
704
703
705
def resources_for ( records , context )
@@ -1067,6 +1069,8 @@ def construct_order_options(sort_params)
1067
1069
end
1068
1070
1069
1071
def _add_relationship ( klass , *attrs )
1072
+ _clear_fields_cache
1073
+
1070
1074
options = attrs . extract_options!
1071
1075
options [ :parent_resource ] = self
1072
1076
@@ -1115,6 +1119,10 @@ def _clear_cached_attribute_options
1115
1119
@_cached_attribute_options = { }
1116
1120
end
1117
1121
1122
+ def _clear_fields_cache
1123
+ @_fields_cache = nil
1124
+ end
1125
+
1118
1126
private
1119
1127
1120
1128
def check_reserved_resource_name ( type , name )
0 commit comments