lib/groupdate/relation_builder.rb in groupdate-4.1.0 vs lib/groupdate/relation_builder.rb in groupdate-4.1.1
- old
+ new
@@ -2,11 +2,11 @@
class RelationBuilder
attr_reader :period, :column, :day_start, :week_start
def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:)
@relation = relation
- @column = column
+ @column = resolve_column(relation, column)
@period = period
@time_zone = time_zone
@time_range = time_range
@week_start = week_start
@day_start = day_start
@@ -170,8 +170,17 @@
op = @time_range.exclude_end? ? "<" : "<="
["#{column} >= ? AND #{column} #{op} ?", @time_range.first, @time_range.last]
else
["#{column} IS NOT NULL"]
end
+ end
+
+ # resolves eagerly
+ # need to convert both where_clause (easy)
+ # and group_clause (not easy) if want to avoid this
+ def resolve_column(relation, column)
+ node = relation.send(:relation).send(:arel_columns, [column]).first
+ node = Arel::Nodes::SqlLiteral.new(node) if node.is_a?(String)
+ relation.connection.visitor.accept(node, Arel::Collectors::SQLString.new).value
end
end
end