mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
17 lines
512 B
Ruby
17 lines
512 B
Ruby
module SerializerHelper
|
|
def ids_to_objs(ids)
|
|
return [] if ids.blank?
|
|
|
|
ids.map { |id| { id: id } }
|
|
end
|
|
|
|
# Returns an array of the fields a serializer needs from it's object
|
|
# so we can #select only what the serializer will actually use
|
|
def required_attributes(model, serializer)
|
|
model_attributes = model.attribute_names
|
|
serializer_attributes = serializer._attributes.keys.map(&:to_s)
|
|
|
|
(serializer_attributes & model_attributes).map { |attr| "#{model.table_name}.#{attr}" }
|
|
end
|
|
end
|