summaryrefslogtreecommitdiff
path: root/app/controllers/api/products_controller.rb
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-16 22:34:51 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-16 22:34:51 -0600
commitf68124a6dff2b0b6131280be2378a049d9d839d4 (patch)
tree4c515695f88b23bf85bbd0e4f66dc6f80b96673a /app/controllers/api/products_controller.rb
parent69153b46eee0fec67efa66f9b5f0499730a98829 (diff)
Mejora las queries
Diffstat (limited to 'app/controllers/api/products_controller.rb')
-rw-r--r--app/controllers/api/products_controller.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb
index 213fa9f..2822a21 100644
--- a/app/controllers/api/products_controller.rb
+++ b/app/controllers/api/products_controller.rb
@@ -49,11 +49,18 @@ module Api
private
def serialized_object
- Serializers::ProductSerializer.new(@product)
+ Serializers::ProductSerializer.new(
+ @product.joins(:company)
+ .select('products.*', 'companies.name as company_name','companies.short_name as company_short_name')
+ )
end
def serialized_collection
- Serializers::ProductSerializer.new(@products.page(params[:page]))
+ Serializers::ProductSerializer.new(
+ @products.joins(:company)
+ .select('products.*', 'companies.name as company_name', 'companies.short_name as company_short_name')
+ .includes(picture_attachment: :blob).page(params[:page])
+ )
end
def permitted_params