1
我想從rails中的此查詢中獲取整數值。如何僅從Rails查詢中獲取值
Inventory.select(:amt_sold).where(item_ID:'GXZ44', store_id:'44555222')
在我的控制,我想選擇我的庫存銷售的量,我想只能從amt_sold
列整數值。當我運行該查詢,我得到:
< Inventory id: nil, amt_sold: 175.0>
如何我剛剛得到的175.0值作爲整數能夠做到就可以了算術運算?
這工作!謝啦!!! – myhouse
我是'#pluck'的粉絲,但在這種情況下它不夠優雅:'Inventory.where(item_ID:'GXZ44',store_id:'44555222')。pluck.first'。你的解決方案更好。 – Tass