Eric Gross
2006-Aug-02 21:21 UTC
[Rails] newbie question, adding conditions to collection of sql objs
I have: @pictures=@c.pictures How do I add limit and order_by conditions. I have tried the following: @c.pictures.find_all(:limit=>5) @c.pictures, :limit=>5 @c.pictures :limit=>5 None of these work. -- Posted via http://www.ruby-forum.com/.
Eric Gross
2006-Aug-02 21:26 UTC
[Rails] Re: newbie question, adding conditions to collection of sql
ok, im using @c.pictures.find(:all, :limit=>5) Is that the right way? Eric Gross wrote:> I have: > > @pictures=@c.pictures > > How do I add limit and order_by conditions. I have tried the following: > > > @c.pictures.find_all(:limit=>5) > > @c.pictures, :limit=>5 > > @c.pictures :limit=>5 > > None of these work.-- Posted via http://www.ruby-forum.com/.
Tom Davies
2006-Aug-02 21:31 UTC
[Rails] Re: newbie question, adding conditions to collection of sql
Yes, that is the right way, and to add an order, just use :order. For example: @model.find(:all, :order => ''created_at DESC'', :limit => 5) On 8/2/06, Eric Gross <tennisbum2002@hotmail.com> wrote:> ok, im using @c.pictures.find(:all, :limit=>5) > > Is that the right way? > Eric Gross wrote: > > I have: > > > > @pictures=@c.pictures > > > > How do I add limit and order_by conditions. I have tried the following: > > > > > > @c.pictures.find_all(:limit=>5) > > > > @c.pictures, :limit=>5 > > > > @c.pictures :limit=>5 > > > > None of these work. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tom Davies http://atomgiant.com http://gifthat.com
Zack Chandler
2006-Aug-02 22:13 UTC
[Rails] newbie question, adding conditions to collection of sql objs
Eric, @c.pictures.find :all, :conditions => [...], :order => ... Zack On 8/2/06, Eric Gross <tennisbum2002@hotmail.com> wrote:> I have: > > @pictures=@c.pictures > > How do I add limit and order_by conditions. I have tried the following: > > > @c.pictures.find_all(:limit=>5) > > @c.pictures, :limit=>5 > > @c.pictures :limit=>5 > > None of these work. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >