Permalink
Browse files

Merge pull request #17 from EddM/master

Ambiguous "id" column when using joins
  • Loading branch information...
2 parents 51d0586 + 74cdc34 commit 5e4c65b3286fee489d46a8e81917259baf5dd852 @alexrabarts committed Oct 20, 2011
Showing with 7 additions and 6 deletions.
  1. +4 −3 lib/big_sitemap.rb
  2. +3 −3 test/big_sitemap_test.rb
View
@@ -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
@@ -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

0 comments on commit 5e4c65b

Please sign in to comment.