diff --git a/app/models/city.rb b/app/models/city.rb index 8f5e73f..4d7f95b 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -42,14 +42,14 @@ class City < ApplicationRecord # 根据数据库类型构建不同的查询 base_query = if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite" joins(<<-SQL.squish) - LEFT JOIN ahoy_events ON + LEFT JOIN ahoy_events ON#{' '} json_extract(ahoy_events.properties, '$.city_id') = cities.id AND json_extract(ahoy_events.properties, '$.event_type') = 'city_view' AND ahoy_events.time > '#{start_time}' SQL else joins(<<-SQL.squish) - LEFT JOIN ahoy_events ON + LEFT JOIN ahoy_events ON#{' '} (ahoy_events.properties::jsonb->>'city_id')::integer = cities.id AND ahoy_events.properties::jsonb->>'event_type' = 'city_view' AND ahoy_events.time > '#{start_time}'