Skip to content

Commit

Permalink
Include aliases in attribute lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jan 30, 2025
1 parent b11cbf9 commit 38d375b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/base_controller/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def normalize_select_attributes(obj, opts)
if opts[:render_attributes].present?
opts[:render_attributes]
elsif obj.respond_to?(:attributes) && obj.class.respond_to?(:virtual_attribute_names)
obj.attributes.keys - obj.class.virtual_attribute_names
(obj.attributes.keys | obj.class.try(:attribute_aliases)&.keys) - obj.class.virtual_attribute_names
elsif obj.respond_to?(:attributes)
obj.attributes.keys
(obj.attributes.keys | obj.class.try(:attribute_aliases)&.keys)
else
obj.keys
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/pictures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def attribute_selection
if !@req.attributes.empty? || @additional_attributes
@req.attributes | Array(@additional_attributes) | ID_ATTRS
else
Picture.attribute_names - %w(content)
Picture.attribute_names | Picture.try(:attribute_aliases)&.keys - %w(content)
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/services/api/options_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ def serialize

def attributes
return [] unless klass
options_attribute_list(klass.attribute_names - klass.virtual_attribute_names)
options_attribute_list((klass.attribute_names | model.try(:attribute_aliases)&.keys) - klass.virtual_attribute_names)
end

def virtual_attributes
return [] unless klass

options_attribute_list(klass.virtual_attribute_names)
end

def relationships
return [] unless klass

(klass.reflections.keys | klass.virtual_reflections.keys.collect(&:to_s)).sort
end

def subcollections
return [] unless klass

Array(config[config.name_for_klass(klass)].subcollections).sort
end

Expand Down

0 comments on commit 38d375b

Please sign in to comment.