Error in migration - Error: You have an error in your SQL syntax; check the manual that corresponds

Cant undestand what wrong with syntax sql file migration. please, help:

i run rake:db:migrate

error:

Mysql2::Error: You have an error in your SQL syntax; check the manual
that
corresponds to your MySQL server version for the right syntax to use
near
‘)’ at line 1: UPDATE photos SET votes_count = 0, rating = 0 WHERE id
NOT
IN
()/home/user/myapp/appmame/db/migrate/20131110162613_recalculate_photos_rating.rb:8:in
`up’

class RecalculatePhotosRating < ActiveRecord::Migration
def up
if Vote.where(“subject_type=‘Photo’ and rating > 1”).count > 0
ActiveRecord::Base.connection.execute “DELETE FROM votes WHERE
subject_type=‘Photo’ AND rating <= 5”
ActiveRecord::Base.connection.execute “UPDATE votes SET rating=1
WHERE subject_type=‘Photo’”
end
pids = Vote.where(subject_type: ‘Photo’).pluck(:subject_id).uniq
ActiveRecord::Base.connection.execute "UPDATE photos SET votes_count

0, rating = 0 WHERE id NOT IN (#{pids.join(’, ‘)})"
ActiveRecord::Base.connection.execute "UPDATE photos SET
rating=(SELECT
COUNT() FROM votes WHERE votes.subject_type=‘Photo’ AND
subject_id=photos.id) WHERE id IN (#{pids.join(’, ')})"
ActiveRecord::Base.connection.execute "UPDATE photos SET
votes_count=(SELECT COUNT(
) FROM votes WHERE votes.subject_type=‘Photo’
AND subject_id=photos.id) WHERE id IN (#{pids.join(’, ')})"
end

def down
end
end

If I am reading your error message correctly:
UPDATE photos SET votes_count = 0, rating = 0 WHERE id NOT IN ()
Looks like your IN Operator is empty. Pretty sure that will throw an
error. If I am correct, I think that you should check the return on
pids.
Otherwise, thanks for this offering… I learned a lot from it.

i inserted

pids = Vote.where(subject_type: ‘Photo’).pluck(:subject_id).uniq
unless pids.empty?

but again same error

пятница, 10 июля 2015 г., 17:27:12 UTC+3 пользователь Elizabeth McGurty
написал:

now work. thank you

пятница, 10 июля 2015 г., 18:05:04 UTC+3 пользователь Dmitriy написал:

No problem… The best thing about this site is the set of fresh
eyes…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs