There's also the arel version: `OrderDetail.joins(:external_service_receiver).where(ExternalServiceReceiver.arel_table[:external_id].matches(query))` which will generate a `LIKE` query (or in the case of postgres, `ILIKE`).