Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prefix primary_columns with table name to avoid ambiguity with joins

  • Loading branch information...
commit 74cdc344fda48b0bd9d53d5b2758918175f4c416 1 parent af5f27f
@EddM EddM authored
Showing with 7 additions and 6 deletions.
  1. +4 −3 lib/big_sitemap.rb
  2. +3 −3 test/big_sitemap_test.rb
View
7 lib/big_sitemap.rb
@@ -132,7 +132,8 @@ def generate_models
find_options[key] = options.delete(key)
end
- primary_column = options.delete(:primary_column)
+ primary_method = options.delete(:primary_column)
+ primary_column = "#{table_name(model)}.#{primary_method}"
count = model.send(count_method, find_options.merge(:select => (primary_column || '*'), :include => nil))
count = find_options[:limit].to_i if find_options[:limit] && find_options[:limit].to_i < count
@@ -185,7 +186,7 @@ def generate_models
priority = options[:priority]
pri = priority.is_a?(Proc) ? priority.call(record) : priority
- last_id = primary_column ? record.send(primary_column) : nil
+ last_id = primary_column ? record.send(primary_method) : nil
sitemap.add_url!(location, last_mod, freq, pri, last_id)
end
end
@@ -254,7 +255,7 @@ def prepare_update
@sources.each do |model, options|
if options[:partial_update] && (primary_column = options[:primary_column]) && (last_id = get_last_id(options[:filename]))
primary_column_value = escape_if_string last_id #escape '
- options[:conditions] = [options[:conditions], "(#{primary_column} >= #{primary_column_value})"].compact.join(' AND ')
+ options[:conditions] = [options[:conditions], "(#{table_name(model)}.#{primary_column} >= #{primary_column_value})"].compact.join(' AND ')
options[:start_part_id] = last_id
end
end
View
6 test/big_sitemap_test.rb
@@ -304,10 +304,10 @@ def teardown
add_model(:num_items => 50) #TestModel
File.open("#{filename}_23.xml", 'w')
- assert_equal "(id >= 23)", @sitemap.send(:prepare_update).first.last[:conditions]
+ assert_equal "(test_models.id >= 23)", @sitemap.send(:prepare_update).first.last[:conditions]
File.open("#{filename}_42.xml", 'w')
- assert_equal "(id >= 23) AND (id >= 42)", @sitemap.send(:prepare_update).first.last[:conditions]
+ assert_equal "(test_models.id >= 23) AND (test_models.id >= 42)", @sitemap.send(:prepare_update).first.last[:conditions]
end
should 'generate correct condition for partial update with custom column' do
@@ -317,7 +317,7 @@ def teardown
add_model(:num_items => 50, :primary_column => 'name') #TestModel
File.open("#{filename}_666.xml", 'w')
- assert_equal "(name >= 666)", @sitemap.send(:prepare_update).first.last[:conditions]
+ assert_equal "(test_models.name >= 666)", @sitemap.send(:prepare_update).first.last[:conditions]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.