reuse existing attribute value query in serializer

This commit is contained in:
drusepth 2021-11-11 15:30:32 -08:00
parent 765ec3c217
commit 0c2a8bfa81

View File

@ -113,7 +113,9 @@ class ContentSerializer
def value_for(attribute_field, content)
case attribute_field.field_type
when 'link'
page_links = attribute_field.attribute_values.find_by(entity_type: content.class.name, entity_id: content.id)
page_links = self.attribute_values.detect do |value|
value.entity_type == content.class.name && value.entity_id == content.id && value.attribute_field_id == attribute_field.id
end
if page_links.nil?
# Fall back on old relation value
# We're technically doing a double lookup here (by converting response