mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Remove another N+1 in product serialization
This commit is contained in:
@@ -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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user