我有一个这样的 SQL 查询:
select *
from orders
where order_session_id IN (
select id order_status
from order_sessions
where order_status IN (
select id
from order_status_types
where order_status != "Paid"
)
)
这返回了一个哈希。我用 ruby 编写了它,但我觉得它可以优化。
@orders = []
paid_order_status_id = OrderStatusType.find_by_order_status("Paid").id
OrderSession.where('order_status != ?',paid_order_status_id).each { |unpaid_order|
@orders << Order.find(unpaid_order.id)
}