Question: Rails: Two 'where' queries - each works individually, but not together

Question

Rails: Two 'where' queries - each works individually, but not together

Answers 1
Added at 2017-03-07 18:03
Tags
Question

I want to write something like:

@meeting_requests = Meeting.where('meeting_time >= ? AND requestee_id IS ? 
                                   AND status = ?', Date.today, nil, "Active")
                           .joins(:requestor)
                           .where('birthyear >= ? AND birthyear <= ?',
                                  current_user.birthyear - 10, 
                                  current_user.birthyear + 10 )

This works:

@meeting_requests = Meeting.where('meeting_time >= ? AND requestee_id IS ? 
                                   AND status = ?', Date.today, nil, "Active")

And this works:

@meeting_requests = Meeting.joins(:requestor)
                           .where('birthyear >= ? AND birthyear <= ?',
                                   current_user.birthyear - 10,
                                   current_user.birthyear + 10 )

And something like this works:

Meeting.joins(:requestor).where('birthyear > ?', 1900).where(status: "Active")

but I need to do a greater than query on the meeting_time, so I need to write it as a string I think?

But together both sql queries produce an error of: ambiguous column name: status: SELECT

I feel like I'm so close... what am I missing here?

Answers to

Rails: Two &#39;where&#39; queries - each works individually, but not together

nr: #1 dodano: 2017-03-07 18:03

This is a message that appears when it is not clear which table the column comes from. This should work:

...rest_of_statement.where('meetings.status' => 'Active')
Source Show
◀ Wstecz