diff options
author | HombreLaser <sebastian-440@live.com> | 2023-03-16 22:34:51 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-03-16 22:34:51 -0600 |
commit | f68124a6dff2b0b6131280be2378a049d9d839d4 (patch) | |
tree | 4c515695f88b23bf85bbd0e4f66dc6f80b96673a /app/controllers/api | |
parent | 69153b46eee0fec67efa66f9b5f0499730a98829 (diff) |
Mejora las queries
Diffstat (limited to 'app/controllers/api')
-rw-r--r-- | app/controllers/api/companies_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/api/products_controller.rb | 11 |
2 files changed, 11 insertions, 4 deletions
diff --git a/app/controllers/api/companies_controller.rb b/app/controllers/api/companies_controller.rb index 086ac5b..973eedb 100644 --- a/app/controllers/api/companies_controller.rb +++ b/app/controllers/api/companies_controller.rb @@ -4,7 +4,7 @@ module Api # CompaniesController class CompaniesController < MasterController def index - @companies = Company.page(params[:page]) + @companies = Company.all render json: serialized_collection.serializable_hash, status: 200 end @@ -44,7 +44,7 @@ module Api end def serialized_collection - Serializers::CompanySerializer.new(@companies.page(params[:page])) + Serializers::CompanySerializer.new(@companies.includes(logo_attachment: :blob).page(params[:page])) end def permitted_params 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 |