I have the following query which looks up an organisation belonging to the current signed in user and then finds any events belonging to that organisation.
def update
@organisation = current_user.organisations.find(params[:organisation_id])
@event = @organisation.events.find(params[:id])
if @event.update_attributes(params[:event])
# Handle a successful update.
flash[:success] = "Event updated"
redirect_to organisation_event_path
else
render 'edit'
end
end
This currently results in 2 queries to the database, which whilst not necessarily a problem, I feel should be able to be achieved in one query. Is that possible or does it need to be 2? If the former, how should I go about achieving it?