Skip to content

Commit

Permalink
Update 20190301075323_add_first_tag_poster.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren authored Mar 7, 2019
1 parent 1493568 commit 1737876
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions db/migrate/20190301075323_add_first_tag_poster.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class AddFirstTagPoster < ActiveRecord::Migration[5.1]
def find_and_update
User.joins(:node).where('node.status = ?', 1).each do |user|
if user.nodes.present?
node = user.nodes.first
node.add_tag('first-time-post', user)
nids = []
User.includes(:node).where(node: { status: 1 }).each do |user|
if user.nodes.count > 1
nids << user.nodes.first.id
end
end
plotsbot = User.find_by(username: 'plotsbot')
Node.find(nids).each do |node|
node.add_tag('first-time-poster', plotsbot)
end
end

def up
Expand Down

0 comments on commit 1737876

Please sign in to comment.