Eager-load and update BasicEnterpriseSerializer

This commit is contained in:
Matt-Yorkley
2020-04-16 01:09:11 +02:00
parent f4bcf6c6d5
commit 9682544442
2 changed files with 15 additions and 3 deletions

View File

@@ -1,9 +1,13 @@
module Admin
class EnterpriseRelationshipsController < ResourceController
def index
@my_enterprises = Enterprise.managed_by(spree_current_user).by_name
@all_enterprises = Enterprise.by_name
@enterprise_relationships = EnterpriseRelationship.by_name.involving_enterprises @my_enterprises
@my_enterprises = Enterprise.
includes(:shipping_methods, :payment_methods).
managed_by(spree_current_user).by_name
@all_enterprises = Enterprise.includes(:shipping_methods, :payment_methods).by_name
@enterprise_relationships = EnterpriseRelationship.
includes(:parent, :child).
by_name.involving_enterprises @my_enterprises
end
def create

View File

@@ -1,4 +1,12 @@
class Api::Admin::BasicEnterpriseSerializer < ActiveModel::Serializer
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category,
:payment_method_ids, :shipping_method_ids, :producer_profile_only, :permalink
def payment_method_ids
object.payment_methods.map(&:id)
end
def shipping_method_ids
object.shipping_methods.map(&:id)
end
end