nullnullnull
nullnullnull

Reputation: 8189

Rails 3: Updating Database Data

I'm trying to follow the instructions here. The final step is to update my database data by using this line of code:

UPDATE rs_reputation_messages SET sender_type = 'ReputationSystem::Evaluation' WHERE sender_type = 'RSEvaluation'

I can't figure out where to put this code. Typically, I'd update the database with a migration, but this looks like a MySQL command. I'm certain there's a very, very simple answer to this question, but despite scouring Google, I can't even figure out how to phrase the question right.

Upvotes: 1

Views: 224

Answers (1)

Salil
Salil

Reputation: 47472

It's always better to create a migration file in such cases. you can use update_all method

RsReputationMessages.update_all("sender_type = 'ReputationSystem::Evaluation'", 
                                "sender_type = 'RSEvaluation'")

OR

ActiveRecord::Base.connection.execute("UPDATE rs_reputation_messages 
                                       SET sender_type = 'ReputationSystem::Evaluation' 
                                       WHERE sender_type = 'RSEvaluation'")

Upvotes: 2

Related Questions