Flowdock

Notes posted by ioev

RSS feed
September 12, 2014
0 thanks

Be careful with .select

With 999 people in the table:

Person.select('person.firstname').find_in_batches do |group|
  group.each { |person| puts person.firstname }
end

Will work properly.

But with 1001 people in the table, this will raise “Primary key not included in the custom select clause”. It’s a bit of a time bomb. If you’re writing tests for methods that use this, you won’t see a failure unless you’ve tested with more than records than the default batch size.