Skip to content

Commit

Permalink
improv: reduce amount of request when fetching pokemons
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienGiboire committed Oct 13, 2021
1 parent 6757c92 commit 23926da
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/pokemons_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Api::PokemonsController < ApplicationController
def index
render json: Pokemon.all, include: ['types']
render json: Pokemon.preload(:pokemon_types, :types).all, include: ['types']
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/pokemon_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PokemonSerializer < ActiveModel::Serializer
has_many :types do
object.types.map do |type|
TypeSerializer.new(type).serializable_hash.merge(
slot: PokemonType.where(type_id: type.id, pokemon_id: object.id).first.slot
slot: object.pokemon_types.where(type_id: type.id).first.slot
)
end
end
Expand Down

0 comments on commit 23926da

Please sign in to comment.