diff --git a/app/models/dunlop/source_file_model.rb b/app/models/dunlop/source_file_model.rb index 6c14429..b9095ef 100644 --- a/app/models/dunlop/source_file_model.rb +++ b/app/models/dunlop/source_file_model.rb @@ -181,15 +181,16 @@ module Dunlop::SourceFileModel def latest_processed if base_class == self join_select = processed.select('MAX(id) AS max_id').group(:sti_type) + #join_select = processed.selecting{ id.maximum.as('max_id')}.group(:sti_type) joins("INNER JOIN (#{join_select.to_sql}) tmp ON id = tmp.max_id") else # return the latest process of the specific source-file class # 2 query based solution, probably faster than the one (sub) query solution - processed.find_by(id: processed.maximum(:id)) + find_by(id: processed.maximum(:id)) ## ONE QUERY SOLUTIONS - # processed.find_by(id: processed.select('MAX(id)')) + # find_by(id: processed.select('MAX(id)')) # OR using baby squeel - # processed.find_by(id: processed.selecting{ id.maximum }) + # find_by(id: processed.selecting{ id.maximum }) end end