From 0c2a8bfa81894d2b9fecba51e223470d57a9c8cd Mon Sep 17 00:00:00 2001 From: drusepth Date: Thu, 11 Nov 2021 15:30:32 -0800 Subject: [PATCH] reuse existing attribute value query in serializer --- app/models/serializers/content_serializer.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/serializers/content_serializer.rb b/app/models/serializers/content_serializer.rb index bddf3a06..f22baa4e 100644 --- a/app/models/serializers/content_serializer.rb +++ b/app/models/serializers/content_serializer.rb @@ -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