Ruby on Rails
Sunday, May 8, 2016
Hi shauna,
Try changing the following part.
.includes(:rsvp_sessions).includes(:event_sessions)
.includes(:
to
.includes([:rsvp_sessions, :event_sessions])
I think you are getting the error because the second call of "includes" overridden the first one.
Thanks,
Genta
On Saturday, May 7, 2016 at 3:26:23 PM UTC-10, shauna wrote:
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?
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/a889d0e3-5107-49c8-930a-75949955ba50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment