Hi all, Does anyone know the difference between find_all and find(:all? I see the documentation for find(:all) on the api: http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000673 But I don''s see find_all anywhere. However find_all is used in many examples, e.g. http://api.rubyonrails.com/classes/ActionController/Pagination.html#M000076 def list @person_pages = Paginator.new self, Person.count, 10, @params[''page''] @people = Person.find_all nil, ''last_name, first_name'', @person_pages.current.to_sql end are these functions identical, and find_all is just shorthand for find(:all) or is there some more subtle difference I am missing? Many thanks in advance CHEERS> SAM
On 9/21/05, Sam Joseph <gaijin-EXQg2k7MwXtHfZP73Gtkiw@public.gmane.org> wrote:> > Hi all, > > Does anyone know the difference between find_all and find(:all? > > I see the documentation for find(:all) on the api: > http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000673 > > But I don''s see find_all anywhere. However find_all is used in many > examples, e.g.Looks like it has been deprecated. You can find the source in deprecated_finders.rb. Here is the doc on it: # This method is deprecated in favor of find(:all, options). # Returns an array of all the objects that could be instantiated from the associated # table in the database. The +conditions+ can be used to narrow the selection of objects (WHERE-part), # such as by "color = ''red''", and arrangement of the selection can be done through +orderings+ (ORDER BY-part), # such as by "last_name, first_name DESC". A maximum of returned objects and their offset can be specified in # +limit+ with either just a single integer as the limit or as an array with the first element as the limit, # the second as the offset. Examples: # Project.find_all "category = ''accounts''", "last_accessed DESC", 15 # Project.find_all ["category = ?", category_name], "created ASC", [15, 20] def find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) Many thanks in advance> CHEERS> SAM > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 9/21/05, Sam Joseph <gaijin-EXQg2k7MwXtHfZP73Gtkiw@public.gmane.org> wrote:> Does anyone know the difference between find_all and find(:all?I am not certain, but my guess is that it would be like what''s been done to the render_* methods. Instead of having all those render_this and render_that, they moved to simply render which then takes parameters like :partial to do the appropriate action. find_all to find(:all) would be consistent with that, and that could explain why find_all is no longer in the documentation.
I *think* that find_all is a method from earlier versions, and is deprecated in favor of find(:all), but maintained for backwards compatibility. On 9/21/05, Sam Joseph <gaijin-EXQg2k7MwXtHfZP73Gtkiw@public.gmane.org> wrote:> Hi all, > > Does anyone know the difference between find_all and find(:all? > > I see the documentation for find(:all) on the api: > http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000673 > > But I don''s see find_all anywhere. However find_all is used in many > examples, e.g. > http://api.rubyonrails.com/classes/ActionController/Pagination.html#M000076 > > def list > @person_pages = Paginator.new self, Person.count, 10, @params[''page''] > @people = Person.find_all nil, ''last_name, first_name'', > @person_pages.current.to_sql > end > > are these functions identical, and find_all is just shorthand for > find(:all) or is there some more subtle difference I am missing? > > Many thanks in advance > CHEERS> SAM > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Many thanks to David, Seth and Pat for your quick responses. With your help I''ve been able to get my paginator working with the find(:all syntax (which is why I was looking into this): def discussed @resource_pages = Paginator.new self, Resource.count( ''discussions.artifact_id = resources.id'', '', discussions''), 5, @params[''page''] @resources = Resource.find(:all, :conditions => ''discussions.artifact_id = resources.id'', :order => ''addeddate'', :joins => '', discussions'', :limit => @resource_pages.items_per_page, :offset => @resource_pages.current.offset) end and thus got pagination over a join, although I notice this is not really a proper join, i.e. the sql looks like this: SELECT COUNT(*) FROM resources , discussions WHERE discussions.artifact_id = resources.id SELECT * FROM resources , discussions WHERE discussions.artifact_id = resources.id ORDER BY addeddate LIMIT 5 So I''m wondering if there is a better way to do this. If I try the following: def discussed @resource_pages = Paginator.new self, Resource.count( ''discussions.artifact_id = resources.id'', '', discussions''), 5, @params[''page''] @resources = Resource.find(:all, :conditions => ''discussions.artifact_id = resources.id'', :order => ''addeddate'', :include => :discussions, :limit => @resource_pages.items_per_page, :offset => @resource_pages.current.offset) end I get the error message "You can not use offset and limit together with has_many or has_and_belongs_to_many associations" [resources has_many:disucssions] so perhaps I just can''t use the paginator with a full join ....? Many thanks in advance. CHEERS> SAM