mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Making sure enterprise serializer serializes no taxons as an empty array
This commit is contained in:
@@ -89,12 +89,12 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
|
||||
def producers
|
||||
relatives = options[:data].relatives[object.id]
|
||||
relatives ? ids_to_objs(relatives[:producers]) : []
|
||||
ids_to_objs(relatives.andand[:producers])
|
||||
end
|
||||
|
||||
def hubs
|
||||
relatives = options[:data].relatives[object.id]
|
||||
relatives ? ids_to_objs(relatives[:distributors]) : []
|
||||
ids_to_objs(relatives.andand[:distributors])
|
||||
end
|
||||
|
||||
# Map svg icons.
|
||||
@@ -139,6 +139,7 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
private
|
||||
|
||||
def ids_to_objs(ids)
|
||||
ids.andand.map { |id| {id: id} }
|
||||
return [] if ids.blank?
|
||||
ids.map { |id| {id: id} }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user