I want to do something like this:
Given:
@user1
@user2
Where the Post model has (id, user_id)
@posts = @user1.posts
I want to take all of the posts of user1, and set the user_id to @user2
Is there an easy one liner way to do this? Or do I have to loop through all the @posts and update attributes and save the record?
Thanks
You can use the class method
update_allon your Post class to accomplish this. The first string passed is essentially the SET clause of an SQL update statement, the second string is the WHERE clause.