codedog
codedog

Reputation: 2508

Ruby Array map for integers

I have this Rails 3.1 ActiveRecord query:

Show.where('event_id = ? AND id not in (?)', params[:event_id], @dog.show_entries.map(&:show_id).join(','))

It worked fine when @dog.show_entries.count == 1. When it had more I had problems with the SQL generated, which was:

SELECT "shows".* FROM "shows" WHERE (event_id = 1 AND id not in ('2,1')) ORDER BY date ASC

How do I stop it from enclosing the 2,1 in quotes?

Upvotes: 0

Views: 201

Answers (1)

Swanand
Swanand

Reputation: 12426

Drop the join(','):

Show.where('event_id = ? AND id not in (?)', params[:event_id], 
  @dog.show_entries.map(&:show_id))

Upvotes: 2

Related Questions