Skip to content

Instantly share code, notes, and snippets.

@umar-siddiqui
Created October 16, 2017 06:46
Show Gist options
  • Save umar-siddiqui/6d3fcd951f63d23950b5ce9cf6b5e651 to your computer and use it in GitHub Desktop.
Save umar-siddiqui/6d3fcd951f63d23950b5ce9cf6b5e651 to your computer and use it in GitHub Desktop.
Mongoid.override_database 'sterlite_resustain_io'
Mongoid::Multitenancy.current_tenant = Client.first
callbacks = IndicatorRecord._save_callbacks.select { |cb| cb.kind == :before }.map { |cb| cb.as_json["key"] }.map(&:to_sym)
indi = Indicator.find('5910150062cee9ae1a000002')
indicator_attri = indi.indicator_attributes.where(attribute_type: 'formula')
IndicatorRecord.skip_callback(:save, :before, *callbacks)
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002', grade: '6th', :start_date.gte => 'June 1,2015', type_of_set: 'Sample', :start_date.lte => 'March 1,2016').each_with_index do |ir,i|
puts i
indicator_attri.each {|ia| ir.recalc_formula(ia) }
ir.save!
end
IndicatorRecord.set_callback(:save, :before, *callbacks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment