Reputation: 17834
How to convert this into an active record query?
select quantity from carts where cart_id = ? and product_id = ?
Upvotes: 1
Views: 86
Reputation: 52346
If you're interested only in the value, and not the overhead of the object (so you're not interested in any of the Cart methods, associations etc), then pluck is available and a little better performing:
Cart.pluck(:quantity).where(:cart_id => cart_id, :product_id => product_id)
Upvotes: 1
Reputation: 107728
Cart.select(:quantity).where(:cart_id => cart_id, :product_id => product_id)
Upvotes: 1