sql - Rails changing query execution order -
i want perform query on first 10 records.
so, rails console type:
log.all.limit(10).where({"username"=>"peeyush"}).explain
this gives:
log load (0.8ms) select "logs".* "logs" "logs"."username" = 'peeyush' limit 10
clearly, limit 10 happens later.
i try running:
log.all.first(10).where({"username"=>"peeyush"}).explain
but gives error:
nomethoderror: undefined method `where' #<array:0x0000000539acd8>
how should query performed?
if understand correctly, want retrieve 1st 10 rows , filter 10 records username?
filter in ruby
all.first(10).find_all {|i| i.username == "peeyush" }
filter on database
all.where(:id => all.first(10).map {|x| x.id}, :username => "peeyush")
Comments
Post a Comment