You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# ModelclassStore < ApplicationRecordhas_many:productshas_many:customershas_many:ordersend# SerializerclassStoreSerializerincludeFastJsonapi::ObjectSerializerattributes:id,:namehas_many:productshas_many:customershas_many:ordersend# I have standard serializer (just like above) for all these models as well.classProduct < ApplicationRecordbelongs_to:storeendclassCustomer < ApplicationRecordhas_many:ordersbelongs_to:storeendclassOrder < ApplicationRecordbelongs_to:storebelongs_to:customerendcustomers=Customer.where(active: true).include(:orders)ShopSerializer.new(customers)
☝️ makes N+1 database calls to Store table. What is the best way to avoid it?
The text was updated successfully, but these errors were encountered:
# Serializerdefinclude_model?(params,model)params[:include].present? && params[:include].include?(model)endhas_many:orders,if: proc{ |_record,params| include_model?(params,:orders)}# Controllercustomers=Customer.where(active: true).include(:orders)ShopSerializer.new(customers,{include: [:orders],params: {include: [:orders]}})# first one for fja include logic, second for params in proc
For example:-
☝️ makes N+1 database calls to Store table. What is the best way to avoid it?
The text was updated successfully, but these errors were encountered: