Skip to content

Commit

Permalink
Fix #find_by (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwestendorf authored Jul 31, 2024
1 parent 59dc1c2 commit fb38675
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/arel/visitors/clickhouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ def aggregate(name, o, collector)
# https://clickhouse.com/docs/en/sql-reference/statements/delete
# DELETE and UPDATE in ClickHouse working only without table name
def visit_Arel_Attributes_Attribute(o, collector)
collector << quote_table_name(o.relation.table_alias || o.relation.name) << '.' unless collector.value.start_with?('DELETE FROM ') || collector.value.include?(' UPDATE ')
collector << quote_column_name(o.name)
if collector.value.is_a?(String)
collector << quote_table_name(o.relation.table_alias || o.relation.name) << '.' unless collector.value.start_with?('DELETE FROM ') || collector.value.include?(' UPDATE ')
collector << quote_column_name(o.name)
else
super
end
end

def visit_Arel_Nodes_SelectOptions(o, collector)
Expand Down
8 changes: 8 additions & 0 deletions spec/single/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class ModelPk < ActiveRecord::Base
end
end

describe '#find_by' do
let!(:record) { Model.create!(id: 1, event_name: 'some event') }

it 'finds the record' do
expect(Model.find_by(id: 1, event_name: 'some event')).to eq(record)
end
end

describe '#reverse_order!' do
it 'blank' do
expect(Model.all.reverse_order!.map(&:event_name)).to eq([])
Expand Down

0 comments on commit fb38675

Please sign in to comment.