Guest User

Untitled

a guest
Feb 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Production.transaction do
  2. Inverter.cache do
  3. params[:productions]['production'].each do |prod|
  4. @ids << Production.find_or_create_by_record_timestamp_and_inverter_id(
  5. :record_timestamp => prod['record_timestamp'],
  6. :inverter_id => Inverter.find_by_serial(prod['inverter']).id,
  7. :kwh_total => prod['kwh_total'],
  8. :irradiance => prod['irradiance'],
  9. :ambient_temp => prod['ambient_temp']
  10. ).id
  11. end
  12. end
  13. end
  14.  
  15. # Example Use and SQL Queries generated by ActiveRecord:
  16.  
  17. # m = {"record_timestamp"=>"09/27/2010 22:26:49", "inverter"=>"2001073445", "kwh_total"=>"-1000", "irradiance"=>"0"}
  18.  
  19. # Production.find_or_create_by_record_timestamp_and_inverter_id(
  20. # :record_timestamp => m['record_timestamp'],
  21. # :inverter_id => Inverter.find_by_serial(m['inverter']).id,
  22. # :kwh_total => m['kwh_total'],
  23. # :irradiance => m['irradiance']
  24. # )
  25.  
  26.  
  27. # Production Load (19.3ms) SELECT "productions".* FROM "productions" WHERE "productions"."record_timestamp" = '09/27/2010 22:26:49' AND "productions"."inverter_id" = 13 LIMIT 1
  28.  
  29. # AREL (21.2ms) INSERT INTO "productions" ("inverter_id", "created_at", "updated_at", "kwh_total", "irradiance", "record_timestamp", "ambient_temp") VALUES (13, '2011-03-11 17:31:12.454028', '2011-03-11 17:31:12.454028', -1000.0, 0.0, NULL, NULL)
Add Comment
Please, Sign In to add comment