|
|
@ -49,15 +49,13 @@ class CostQuery::SqlStatement |
|
|
|
# @return [CostQuery::SqlStatement] Generated statement |
|
|
|
# @return [CostQuery::SqlStatement] Generated statement |
|
|
|
def self.unified_entry(model) |
|
|
|
def self.unified_entry(model) |
|
|
|
table = table_name_for model |
|
|
|
table = table_name_for model |
|
|
|
Rails.cache.fetch("unified_#{table}") do |
|
|
|
new(table).tap do |query| |
|
|
|
new(table).tap do |query| |
|
|
|
query.select COMMON_FIELDS |
|
|
|
query.select COMMON_FIELDS |
|
|
|
query.select({ |
|
|
|
query.select({ |
|
|
|
:type => model.model_name.inspect, :count => 1, :id => [model, :id], |
|
|
|
:type => model.model_name.inspect, :count => 1, :id => [model, :id], |
|
|
|
:real_costs => switch("#{table}.overridden_costs IS NULL" => [model, :costs], :else => [model, :overridden_costs]) |
|
|
|
:real_costs => switch("#{table}.overridden_costs IS NULL" => [model, :costs], :else => [model, :overridden_costs]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
send("unify_#{table}", query) |
|
|
|
send("unify_#{table}", query) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|