Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Production.transaction do
- Inverter.cache do
- params[:productions]['production'].each do |prod|
- @ids << Production.find_or_create_by_record_timestamp_and_inverter_id(
- :record_timestamp => prod['record_timestamp'],
- :inverter_id => Inverter.find_by_serial(prod['inverter']).id,
- :kwh_total => prod['kwh_total'],
- :irradiance => prod['irradiance'],
- :ambient_temp => prod['ambient_temp']
- ).id
- end
- end
- end
- # Example Use and SQL Queries generated by ActiveRecord:
- # m = {"record_timestamp"=>"09/27/2010 22:26:49", "inverter"=>"2001073445", "kwh_total"=>"-1000", "irradiance"=>"0"}
- # Production.find_or_create_by_record_timestamp_and_inverter_id(
- # :record_timestamp => m['record_timestamp'],
- # :inverter_id => Inverter.find_by_serial(m['inverter']).id,
- # :kwh_total => m['kwh_total'],
- # :irradiance => m['irradiance']
- # )
- # 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
- # 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