Skip to content

Instantly share code, notes, and snippets.

@rjswenson
Created October 9, 2015 23:08
Show Gist options
  • Save rjswenson/9e8519f3228130629622 to your computer and use it in GitHub Desktop.
Save rjswenson/9e8519f3228130629622 to your computer and use it in GitHub Desktop.
Change Mongoid object w/o callbacks
#
Document.where(:wholesale_price_group.ne => nil, :total_prices.ne => {}).each do |doc|
wsl = doc.total_prices[doc.wholesale_price_group]
Document.collection.where({_id: doc.id}).update({
"$set" => { :wholesale_total => wsl }
})
end
@rjswenson
Copy link
Author

Document.each do |doc|
  qty = doc.get_product_quantities
  Document.collection.where({_id: doc.id}).update({
  "$set" => {:product_quantities => qty} })    
end


  def get_product_quantities
    sq = {}
    pages.each do |page|
      page.page_products.each do |pp|
        sq[pp.product_number] ||= 0
        sq[pp.product_number] += pp.total_units.to_i
      end
    end
    sq
  end

@rjswenson
Copy link
Author

[array of document numbers].each do |num|
  doc = Document.where(number: num).first
  if /-05$/ =~ doc.customer
    doc.submit_backend
  else
    Document.collection.where({_id: doc.id}).update({
      "$set" => {:customer => doc.customer + "-05"} })
    doc.pages.each do |page|
      page.customer_number = page.customer_number + "-05"
      page.save
    end
    doc.submit_backend
  end
end

DOZUSENO | OR04
BIJOHOTSUJI | SO12
SEGOPITA | ZO02-05
BIKACHIDEDO | ZO02-05
SEKUDUGE | OU47-05
BEHEBUJIFU | OU41-05
BESUHANEPI | SO12-05
BIMIDOCHIMU| SO13-05
BETZUTOGIYO | CA29
BIMUKEMIJO | ZO02
FUKOYOHI | OU41
GUSETEHO | SO13
BIMEDABEMO | KU06 |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment