I tried to reproduce your problem, but failed (Rails 3.2.2, too, using the sqlite3 adapter, code below). But try this anyway:
Article.uncached do Article.order('RAND()').limit(3).inspect end
The following is an example of how I tried to reproduce your problem in an empty Rails project; for me, this still led the articles in a different order:
ActiveRecord::Migration.create_table :articles do |t| t.string :name end
class Article < ActiveRecord::Base; end
20.times do |i| Article.create :name => "Article#{i}" end
Article.connection.instance_variable_get(:@connection).define_function 'RAND' do rand end
p *Article.order('RAND()').limit(3)
You may have noticed a mistake in the way I tried to reproduce your problem.
source
share