I have the following code
class Tour < ApplicationRecord
has_one :first_action, -> { order(scheduled_start_at: :desc) },
class_name: 'TourAction',
dependent: :nullify,
inverse_of: :tour
def date
first_action.scheduled_start_at
end
When I am exposing the date field on my grape entity
expose(
:date,
documentation: {
type: DateTime,
desc: 'The date of the tour',
example: '2023-03-07T10:54:10+01:00'
}, format_with: :iso8601
)
Bullet is giving me the use eager loading warning
2023-04-04 13:48:30[WARN] user: root
GET /api/v2/vehicles/2d836de7-27cb-4e64-854d-ad26d9063cc8/tours
USE eager loading detected
Tour => [:first_action]
Add to your query: .includes([:first_action])
Call stack
/app/app/models/tour.rb:73:in `date'
How can I fix this?