Forum: Ruby on Rails Sql query vs Ruby methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nike M. (Guest)
on 2009-04-22 17:35
In am using the following code in my application,both the applications
execute the same result.First one executes fastly than the second
one,How can i modify the second one since it is fetching all the values,
from there it is limiting  5 rather than the first one

User.all.find(:all,:conditions=>["id not
in(?)",Person.all],:limit=>5,:order=>'created_at DESC')


User.all.find(:all,:order=>'created_at DESC').delete_if{|x| x id
Person.all.include?(x)}[0..4]
Dmitry S. (Guest)
on 2009-04-22 17:48
(Received via mailing list)
Really both quieries look crazy, and will perform poorly on any
realistic dataset.

I guess Person is a subclass of a User, so if you are using STI just
try:

User.all(:conditions => "type !=
'Person'", :limit=>5, :order=>'created_at DESC')

Dmitry
Nike M. (Guest)
on 2009-04-22 18:18
Dmitry S. wrote:
> Really both quieries look crazy, and will perform poorly on any
> realistic dataset.
>
> I guess Person is a subclass of a User, so if you are using STI just
> try:
>
> User.all(:conditions => "type !=
> 'Person'", :limit=>5, :order=>'created_at DESC')
>
> Dmitry

Thanks
This topic is locked and can not be replied to.