I am having "Order" model with pickup_date, delivery_date and status. So i want to select orders -
(eg, '12/12/2012')
(eg, '12/12/2012')
I think we can use WHEN CASE
with Activerecord. Can anybody help me in this?
Order.where("(status = 'pickup_up' AND pickup_date = :date) OR (status = 'delivered' AND delivery_date = :date)", date: Date.today)
在Rails 5中,您实际上已经可以对ActiveRecord关系使用“或”方法:
Order.where(status: :picked_up, pickup_date: Date.today).or(Order.where(status: :delivered, delivery_date: Date.today))
In addition to @M. Stavnycha answer, Rails has a great section on ActiveRecord query interface available here http://guides.rubyonrails.org/active_record_querying.html
Order.where(status: :picked_up).update(:pickup_date '12/12/2012')
Order.where(status: :delivered).update(:delivery_date '12/12/2012')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.