Ruby on Rails
Saturday, May 7, 2016
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?
-- 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?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e05597a6-88d9-49aa-a296-85362d9ae75c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment