class UserWechat < ActiveRecord::Base attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country, :headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id, :bindtype belongs_to :user def real? bindtype == 0 end def migrate_user(u) self.bindtype = 0 old_user = user.id self.user = u self.save ## 主要是将comment 迁移 User.delete(old_user) JournalsForMessage.where(user_id: old_user).update_all(user_id: u.id) Journal.where(user_id: old_user).update_all(user_id: u.id) Comment.where(author_id: old_user).update_all(author_id: u.id) Message.where(author_id: old_user).update_all(author_id: u.id) BlogComment.where(author_id: old_user).update_all(author_id: u.id) UserActivity.where(user_id: old_user).update_all(user_id: u.id) end def unsubscribe! self.delete end end