Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #17 from EddM/master

Ambiguous "id" column when using joins
  • Loading branch information...
commit 5e4c65b3286fee489d46a8e81917259baf5dd852 2 parents 51d0586 + 74cdc34
Alex Rabarts authored October 20, 2011
7  lib/big_sitemap.rb
@@ -132,7 +132,8 @@ def generate_models
132 132
           find_options[key] = options.delete(key)
133 133
         end
134 134
 
135  
-        primary_column   = options.delete(:primary_column)
  135
+        primary_method   = options.delete(:primary_column)
  136
+        primary_column   = "#{table_name(model)}.#{primary_method}"
136 137
 
137 138
         count = model.send(count_method, find_options.merge(:select => (primary_column || '*'), :include => nil))
138 139
         count = find_options[:limit].to_i if find_options[:limit] && find_options[:limit].to_i < count
@@ -185,7 +186,7 @@ def generate_models
185 186
               priority = options[:priority]
186 187
               pri = priority.is_a?(Proc) ? priority.call(record) : priority
187 188
 
188  
-              last_id = primary_column ? record.send(primary_column) : nil
  189
+              last_id = primary_column ? record.send(primary_method) : nil
189 190
               sitemap.add_url!(location, last_mod, freq, pri, last_id)
190 191
             end
191 192
           end
@@ -254,7 +255,7 @@ def prepare_update
254 255
     @sources.each do |model, options|
255 256
       if options[:partial_update] && (primary_column = options[:primary_column]) && (last_id = get_last_id(options[:filename]))
256 257
         primary_column_value       = escape_if_string last_id #escape '
257  
-        options[:conditions]       = [options[:conditions], "(#{primary_column} >= #{primary_column_value})"].compact.join(' AND ')
  258
+        options[:conditions]       = [options[:conditions], "(#{table_name(model)}.#{primary_column} >= #{primary_column_value})"].compact.join(' AND ')
258 259
         options[:start_part_id]    = last_id
259 260
       end
260 261
     end
6  test/big_sitemap_test.rb
@@ -304,10 +304,10 @@ def teardown
304 304
         add_model(:num_items => 50) #TestModel
305 305
 
306 306
         File.open("#{filename}_23.xml", 'w')
307  
-        assert_equal "(id >= 23)", @sitemap.send(:prepare_update).first.last[:conditions]
  307
+        assert_equal "(test_models.id >= 23)", @sitemap.send(:prepare_update).first.last[:conditions]
308 308
 
309 309
         File.open("#{filename}_42.xml", 'w')
310  
-        assert_equal "(id >= 23) AND (id >= 42)", @sitemap.send(:prepare_update).first.last[:conditions]
  310
+        assert_equal "(test_models.id >= 23) AND (test_models.id >= 42)", @sitemap.send(:prepare_update).first.last[:conditions]
311 311
       end
312 312
 
313 313
       should 'generate correct condition for partial update with custom column' do
@@ -317,7 +317,7 @@ def teardown
317 317
         add_model(:num_items => 50, :primary_column => 'name') #TestModel
318 318
 
319 319
         File.open("#{filename}_666.xml", 'w')
320  
-        assert_equal "(name >= 666)", @sitemap.send(:prepare_update).first.last[:conditions]
  320
+        assert_equal "(test_models.name >= 666)", @sitemap.send(:prepare_update).first.last[:conditions]
321 321
       end
322 322
     end
323 323
 

0 notes on commit 5e4c65b

Please sign in to comment.
Something went wrong with that request. Please try again.