diff --git a/app/controllers/api/pokemons_controller.rb b/app/controllers/api/pokemons_controller.rb index d5b4e02..943aad9 100644 --- a/app/controllers/api/pokemons_controller.rb +++ b/app/controllers/api/pokemons_controller.rb @@ -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 diff --git a/app/serializers/pokemon_serializer.rb b/app/serializers/pokemon_serializer.rb index 734cfd8..29cb2c4 100644 --- a/app/serializers/pokemon_serializer.rb +++ b/app/serializers/pokemon_serializer.rb @@ -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