Skip to content

Instantly share code, notes, and snippets.

@phensalves
Created May 11, 2017 15:44
Show Gist options
  • Save phensalves/445016bc95a7fd991954725373ff9788 to your computer and use it in GitHub Desktop.
Save phensalves/445016bc95a7fd991954725373ff9788 to your computer and use it in GitHub Desktop.
Maneiras de se fazer queries
operations = Operation.all
states = CountryState.all
states.each do |s|
operations.each do |operation|
next if (operation.name == "Teste" || operation.name == "teste" || operation.name == "TESTE")
case s.name
when "Amazonas"
operation.country_state_id = 1 if operation.name == "CDD MANAUS"
when "Bahia"
operation.country_state_id = 2 if (operation.name == "CDD Salvador" ||
operation.name == "SALVADOR")
when "Ceará"
operation.country_state_id = 3 if operation.name == "CDD Fortaleza"
end
end
end
===============================================================================================================================
update_belem_bars
puts "========================= END OF PROCESS TO SET OPERATIONS TO BELEM BARS... ========================="
update_belo_horizonte_bars
puts "========================= END OF PROCESS TO SET OPERATIONS TO BELO HORIZONTE BARS... ========================="
private
def update_operation_bars(bars, operation_id)
bars.each do |bar|
bar.operation_id = operation_id unless bar.operation_id.present?
bar.save(:validate => false) if bar.operation_id == operation_id
end
end
def update_belem_bars
load_no_operation_belem_bars
update_operation_bars(@belem_bars, 20)
end
def update_belo_horizonte_bars
load_no_operation_bh_bars
update_operation_bars(@bh_bars, 13)
end
def load_no_operation_belem_bars
@belem_bars = build_query(10)
end
def load_no_operation_bh_bars
@bh_bars = build_query(5)
end
def build_query city_id
Bar.includes(:city).where(cities: {id: "#{city_id}"}).where("operation_id IS NULL")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment