I have a method that calls Model.find(:first, :order => "RAND()")
twice. I want it to return two different results but it always returns
the same thing twice. Is there some kind of sql caching at work here?
If so, can I disable for this method?
First of all, I'm assuming you are calling rand() (lowercase).
rand() returns a value less than between 0 and 1.
Using this as the call to :order tells the database to use the column
reference (rather than a name).
In MySQL, if you pass a non-integer column value, it gets ignored.
(Not sure how other databases handle it).
I don't really understand what you are trying to randomize in your
order parameter.
You should probably get the count of the records in your table and
generate a random number between 1 and that count. Then use offset to
select that record.
First of all, I'm assuming you are calling rand() (lowercase).
Case isn't significant.
I don't really understand what you are trying to randomize in your
order parameter.
You should probably get the count of the records in your table and
generate a random number between 1 and that count. Then use offset to
? The syntax below works just fine to return a random instance of
Model.
I have a method that calls Model.find(:first, :order => "RAND()")
twice. I want it to return two different results but it always returns
the same thing twice.
What it *doesn't* do is guarantee that any two randomly selected
instances won't be the same