我正在使用Ruby on Rails 2.3.8,並且想要獲取尚未添加到listed_products
陣列的所有@products
。如何在以下情況下模擬NOT IN SQL條件
例如,假設我有以下代碼:
listed_products = ['1', '2', '3', '4', '5']
#Then, I would like to do something like SELECT * FROM products where id not in
#(listed_products), and save the result in @products
我知道上面的SQL語法將無法正常工作,但我只是想給你們的我想要什麼的想法實現。
這樣做有沒有「軌道方式」?
提前致謝!
這似乎是重複的:http://stackoverflow.com/questions/4818466/rails -find-records-that-are-present-another-join-table/4818822#4818822 – Nuby 2011-02-08 19:03:01