如何在rails中的两个字段上进行查询?

时间:2015-08-17 15:30:47

标签: ruby-on-rails ruby-on-rails-4

如果id在其中一个字段sender_id或recipient_id中根据他进行选择,如何对两个字段sender_id或recipient_id进行查询

查询

@recipients = Company.joins(:invitations).where(invitations: {sender_id: @company.id OR recipient_id: @company.id,confirm: true})

1 个答案:

答案 0 :(得分:0)

 @recipients = Company.joins(:invitations).where("invitations.confirm = ? and (invitations.sender_id = ? or invitations.recipient_id = ?)", true, @company.id, @company.id)