0
In the index method of the controller Disputes::ConferencesController
list all the conferences
of disputes
. The URL address is disputes/1/conferences
.
My route schema is like this:
resources :disputes do
scope module: :disputes do
resources :conferences, shallow: true
end
end
Unfortunately to get the conferences
I need to do 2 queries in the database:
Dispute Load (0.3ms) SELECT "disputes".* FROM "disputes" WHERE "disputes"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Conference Load (0.4ms) SELECT "conferences".* FROM "conferences" WHERE "conferences"."dispute_id" = $1 ORDER BY "conferences"."scheduled_at" DESC [["dispute_id", 1]]
The method index
is that way:
def set_dispute
@dispute = Dispute.find params[:dispute_id]
end
def index
@conferences = @dispute.conferences.order(scheduled_at: :desc)
render json: @conferences, each_serializer: ConferencesSerializer
end
How to get around this for only 1 query?