Remove another N+1 in product serialization

This commit is contained in:
Matt-Yorkley
2020-04-07 15:22:00 +02:00
parent f959e632ea
commit b0a7497f2a

View File

@@ -1,9 +1,12 @@
class Api::Admin::ProductSimpleSerializer < ActiveModel::Serializer
attributes :id, :name
attributes :id, :name, :producer_id
has_one :supplier, key: :producer_id, embed: :id
has_many :variants, key: :variants, serializer: Api::Admin::VariantSimpleSerializer
def producer_id
object.supplier_id
end
def on_hand
return 0 if object.on_hand.nil?