我有两个模型
Order has_many State(s)
State belongs_to Order
a State has an attribute named 'kind'
我试图用活动记录表达以下查询:'所有具有 current_state.kind = :something 的订单',
current_state 是订单的最后创建状态。
我还在模型中添加了 :current_state 作为 has_one 关联:
has_one :current_state, -> { order('created_at DESC').limit(1) }, class_name: 'State'
但这无济于事