2016-10-22 42 views
0

我試圖用where.not替換下列麻煩:有使用where.not在軌

if @friend_matches.count > 0 
    @court_matches = Match.available_on_courts.where('matches.id NOT IN (?)', @friend_matches.pluck(:id)).to_a 
else 
    @court_matches = Match.available_on_courts 
end 

隨着

@court_matches = Match.available_on_courts.where.not(matches.id: @friend_matches.pluck(:id)).to_a 

但是我收到以下錯誤。

SyntaxError: /Users/sripaladugu/Coding/matchpoint_rails/app/mailers/match_mailer.rb:8: syntax error, unexpected ':' 
...on_courts.where.not(matches.id: @friend_matches.pluck(:id)).... 
...        ^
/Users/sripaladugu/Coding/matchpoint_rails/app/mailers/match_mailer.rb:8: syntax error, unexpected ')', expecting keyword_end 
...id: @friend_matches.pluck(:id)).to_a 

回答

2

可以內where提供一個哈希作爲第二級中的按鍵和列名指定表名:

@court_matches = Match.available_on_courts 
         .where.not(matches: { id: @friend_matches.pluck(:id) }) 
         .to_a 
+0

感謝您的快速回復。這解決了這個問題。 – calilonghorn

+0

不客氣。 –