This commit is contained in:
邱博亞 2023-03-03 22:00:53 +08:00
parent 9e54e1794c
commit cc81f41a57
1 changed files with 8 additions and 8 deletions

View File

@ -2,13 +2,13 @@ namespace :personal_journal do
desc 'set_journal_type'
task :set_journal_type => :environment do |task,args|
JournalPaper.where(:rss2_id.ne=>nil).update_all({"$unset"=>{"journal_type_ids"=>""}})
MemberTag.all.each do |mt|
journal_type = JournalType.where(:title=>mt.title).first
journal_type = JournalType.create(:title_translations=>mt.title_translations) if journal_type.nil?
journal_type_id = journal_type.id
journal_paper_ids = JournalPaper.where(:member_profile_id.in=>mt.member_profile_ids, :rss2_id.ne=>nil).pluck(:id)
JournalPaper.where(:id.in=>journal_paper_ids).update_all({"$addToSet"=>{"journal_type_ids"=>journal_type.id}})
# JournalType.where(:id=>journal_type_id).update_all({"$addToSet"=>{"journal_paper_ids"=>{"$each"=>journal_paper_ids}}})
end
MemberTag.all.each do |mt|
journal_type = JournalType.where(:title=>mt.title).first
journal_type = JournalType.create(:title_translations=>mt.title_translations) if journal_type.nil?
journal_type_id = journal_type.id
journal_paper_ids = JournalPaper.where(:member_profile_id.in=>mt.member_profile_ids, :rss2_id.ne=>nil).pluck(:id)
JournalPaper.where(:id.in=>journal_paper_ids).update_all({"$addToSet"=>{"journal_type_ids"=>journal_type.id}})
# JournalType.where(:id=>journal_type_id).update_all({"$addToSet"=>{"journal_paper_ids"=>{"$each"=>journal_paper_ids}}})
end
end
end