I'm literally just a few days old from learning Rails and I'm currently working on queries using scopes.
I have this simplified code:
Class Product < ActiveRecord::Base
belongs_to: producer
scope: get_items, => {where.not(producer{id: nil})}
Firing up rails c
and typing in Product.get_items
it instead produces:
SELECT "products".* FROM "products" WHERE (producer_id IS NULL)
when I needed:
SELECT "products".* FROM "products" WHERE (producer_id IS NOT NULL)
Did some research and also tried {where("producer_id IS NOT NULL")}
but doesn't make the query different.
Thanks in advance!
Product.where.not(producer_id: nil)
does it work? - Ravi Mariyascope :get_items, (lambda do where.not(producer_id: nil) end)
- Rohit Lingayat