Hi all,
So I am trying to render the following component that calls my get_remaining_time function, passing in @truck_load:
<CardInfo label="Time Since Available" title={{ get_remaining_time(@truck_load) }} small />
Here is my get_remaining_time
function:
defp get_remaining_time(truck_load) do
current_truck_load = %TruckLoad{
pull_point: truck_load.pull_point,
well: %Well{id: truck_load.well_id}
}
driver = TSS.DriverStatuses.list_assignable_drivers_by_truck_load(current_truck_load)
time_elapsed = Formatters.decorate_time_since_available(driver)
"#{time_elapsed} (hh:mm)"
end
It calls the list_assignable_drivers_by_truck_load
function, which looks like this:
def list_assignable_drivers_by_truck_load(%TruckLoad{
well: %{id: well_id},
pull_point: pull_point
}) do
base_assignable_drivers_query()
|> apply_default_select(pull_point.point)
|> filter({:well_id, well_id})
|> sort({:distance_in_meters, :asc}, %{"pull_point_id" => pull_point.id})
|> preload(driver: [:trailer_type, driver_contract: [:carrier]])
|> Repo.all()
end
However, I am getting this error:
(KeyError) key :pull_point not found in: ~huge map of truck_load
's contents~
The truck_load
map has a pull_point
key, but it’s value is pull_point: #Ecto.Association.NotLoaded<association :pull_point is not loaded>
I believe I need to preload pull_point
, but I shouldn’t do that on the front end, right? I’m not sure how else to access that data though…
Thank you so much for any help!!