0
I am using Activerecord to run queries in several different databases. In one of the queries, I have to do the following:
publications_to_read = [1,2,3,4]
ActiveRecord::Base.connection.execute("ALTER TABLE publications SET readed = TRUE WHERE id IN (#{publications_to_read});")
If I were doing this from a class I inherited from ActiveRecord::Base
, there would be a much more intuitive way to do this, but that’s not the case.
What I need is to interpolate this array in the query so that the final result looks like this:
publications_to_read = [1,2,3,4]
# Query usando o array adaptado
ActiveRecord::Base.connection.execute("ALTER TABLE publications SET readed = TRUE WHERE id IN ('1', '2', '3', '4');")
Can anyone tell me how I could achieve this result? I’ve tried to do something like publications_to_read.join(',')
but it didn’t work. The array is converted into a single String and gives error.