D
D
dexdev2015-08-17 18:21:08
Ruby on Rails
dexdev, 2015-08-17 18:21:08

How to query on two fields in rails?

How to correctly write a query to select from a table by two fields, if the id matches in the sender_id column or in the recipient_id column, then take them together?
@recipients = Company.joins(:invitations).where(invitations: {sender_id: @company.id OR recipient_id: @company.id ,confirm: true})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
thepry, 2015-08-17
@AdilA

Company.joins(:invitations).where('invitations.sender_id = ? OR invitations.recipient_id = ? ', @company.id, @company.id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question