Accessing a PostgreSQL 9.4.4 database, I have code like:
previous_rsvps = Rsvp
.select('rsvp.user_id', '
event_sessions.name')
.where(user_id: selected_attendees).includes(:rsvp_sessions).includes(:event_sessions)
.where("event_sessions.event_id IS NOT NULL")
.where("
event_sessions.name ~* ? OR
event_sessions.name !~* ?",
"Workshop", "Installfest")
I believe this retrieves the expected records, because if I follow it with a command:
previous_rsvps.pluck('
event_sessions.name').uniq.sort
then the correct names are listed.
However, if I give the command:
previous_rsvps.count
then I get the error message:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "rsvp".
Of course, I'm looking to do more with the previous_rsvps object, but this example captures the error. What causes this error and how do I get around it?