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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -