Ruby on rails 具有NOT运算符的多个关联联接查询
我有以下非常有效的Rails查询:-Ruby on rails 具有NOT运算符的多个关联联接查询,ruby-on-rails,ruby-on-rails-4,activerecord,rails-activerecord,ruby-on-rails-4.1,Ruby On Rails,Ruby On Rails 4,Activerecord,Rails Activerecord,Ruby On Rails 4.1,我有以下非常有效的Rails查询:- @basic = Pay.joins(:ee_pay => :company_pay).where(:pays => {pay_line_id: current_pay_line.id, pay_sub_head_id: 1}, :company_pays => {:description => 'Salary'}).first 我现在正试图写一些不一样的东西,但失败得很惨。我原以为这样行得通,但它总是给我错误:- @other_p
@basic = Pay.joins(:ee_pay => :company_pay).where(:pays => {pay_line_id: current_pay_line.id, pay_sub_head_id: 1}, :company_pays => {:description => 'Salary'}).first
我现在正试图写一些不一样的东西,但失败得很惨。我原以为这样行得通,但它总是给我错误:-
@other_pay = Pay.joins(:ee_pay => :company_pay).where(:pays => {pay_line_id: current_pay_line.id, pay_sub_head_id: 1}, :company_pays => {('description != ?', "Salary")})
还尝试了这个和其他一些变体:-
@other_pay = Pay.joins(:ee_pay => :company_pay).where(:pays => {pay_line_id: current_pay_line.id, pay_sub_head_id: 1}).where(:company_pays => ['description != ?', "Salary"])
有人能告诉我如何在多重关联联接查询中放置NOT运算符吗?您可以在Rails 4中尝试使用
.NOT()
:
@other_pay = Pay.joins(ee_pay: :company_pay)
.where(pays: {pay_line_id: current_pay_line.id, pay_sub_head_id: 1})
.where.not(company_pays: {description: "Salary"})
Rails版本是4.1.0