PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using joins and where

Hmm it looks like you’re trying to include current_orders and include order. Are these the same tables with different conditions? This might be confuse active record. Also, I’m pretty sure it’s wise to include the references method when referencing a joined table. Perhaps, try something like this:

active_couriers = Courier.includes(:orders)
  .available_courier_status
  .where(:service_region_id => @service_region.id)
  .where("orders.created_at >= ?", Time.zone.now.beginning_of_day)
  .references(:orders)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)