Skip to content

Commit

Permalink
Fix ambiguous column error (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
frvade authored May 25, 2020
1 parent 6b0116a commit 9e9b5de
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.3

Naming/UncommunicativeMethodParamName:
Naming/MethodParameterName:
Enabled: false
5 changes: 3 additions & 2 deletions lib/sequel/extensions/batches/yielder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def call
base_ds
end

current_instance = db.from(working_ds.limit(of)).select(*pk).order(*pk).last or break
working_ds_pk = working_ds.select(*qualified_pk).limit(of)
current_instance = db.from(working_ds_pk).select(*pk).order(*pk).last or break
working_ds = working_ds.where(generate_conditions(current_instance.to_h, sign: :<=))

yield working_ds
Expand Down Expand Up @@ -67,7 +68,7 @@ def setup_base_ds
base_ds = base_ds.where(generate_conditions(check_pk(start), sign: :>=)) if start
base_ds = base_ds.where(generate_conditions(check_pk(finish), sign: :<=)) if finish

pk_ds = db.from(base_ds).select(*pk).order(*pk)
pk_ds = db.from(base_ds.select(*qualified_pk)).select(*pk).order(*pk)
actual_start = pk_ds.first
actual_finish = pk_ds.last

Expand Down
4 changes: 2 additions & 2 deletions sequel-batches.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "sequel-batches"
spec.version = "1.0.0"
spec.authors = ["fiscal-cliff", "umbrellio"]
spec.version = "1.0.1"
spec.authors = %w[fiscal-cliff umbrellio]
spec.email = ["[email protected]"]

spec.summary = "The extension mimics AR5 batches api"
Expand Down
4 changes: 4 additions & 0 deletions spec/sequel/extensions/batches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@
it "raises MissingPKError in case of missing pk" do
expect { DB[:points].in_batches {} }.to raise_error(Sequel::Extensions::Batches::MissingPKError)
end

it "qualifies pk to mitigate ambiguous column error" do
expect { DB[:data, :data2].in_batches {} }.not_to raise_error
end
end
16 changes: 9 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ def connect
config.before(:all) do
DB.extension :batches

DB.drop_table?(:data)
DB.create_table?(:data) do
primary_key :id
column :created_at, "text"
column :value, "int"
%i[data data2].each do |table|
DB.drop_table?(table)
DB.create_table?(table) do
primary_key :id
column :created_at, "text"
column :value, "int"
end

DB[table].multi_insert(YAML.load_file("./spec/fixtures/data.yml"))
end

DB[:data].multi_insert(YAML.load_file("./spec/fixtures/data.yml"))

DB.drop_table?(:points)
DB.create_table?(:points) do
column :x, "int"
Expand Down

0 comments on commit 9e9b5de

Please sign in to comment.