如果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})
答案 0 :(得分:0)
@recipients = Company.joins(:invitations).where("invitations.confirm = ? and (invitations.sender_id = ? or invitations.recipient_id = ?)", true, @company.id, @company.id)