Hi everyone, I have GroupDocument model with following fields: belongs_to :group belongs_to :document enum_attr :status, %w(pending approved banned) Document has fields like ''title'' or ''author''. On controller index I do: @group_documents GroupDocument.find_all_by_group_id(params[:group_id]).paginate :page => params[:page], :per_page => 10, :order => ''?'' Problem is with order. I want to return @group_documents collection ordered by document.title. Something like :order => ''group.title asc'' How is it possible? Cheers Alex -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 15, 8:44 am, Alex Djioev <dji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @group_documents > GroupDocument.find_all_by_group_id(params[:group_id]).paginate :page > => params[:page], :per_page => 10, :order => ''?'' > > Problem is with order. I want to return @group_documents collection > ordered by document.title. Something like > :order => ''group.title asc''You need to join the groups table, then you''ll be able to order by groups.title Fred> > How is it possible? > > Cheers Alex-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred, thanks for replay. Can you give me an example please, I''m not that good with queries. Cheers Alex On Apr 15, 6:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 15, 8:44 am, Alex Djioev <dji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > @group_documents > > GroupDocument.find_all_by_group_id(params[:group_id]).paginate :page > > => params[:page], :per_page => 10, :order => ''?'' > > > Problem is with order. I want to return @group_documents collection > > ordered by document.title. Something like > > :order => ''group.title asc'' > > You need to join the groups table, then you''ll be able to order by > groups.title > > Fred > > > > > How is it possible? > > > Cheers Alex > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred, thanks for replay. Can you give me an example please, I''m not that good with queries. Cheers Alex On Apr 15, 6:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 15, 8:44 am, Alex Djioev <dji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > @group_documents > > GroupDocument.find_all_by_group_id(params[:group_id]).paginate :page > > => params[:page], :per_page => 10, :order => ''?'' > > > Problem is with order. I want to return @group_documents collection > > ordered by document.title. Something like > > :order => ''group.title asc'' > > You need to join the groups table, then you''ll be able to order by > groups.title > > Fred > > > > > How is it possible? > > > Cheers Alex > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred, thanks for replay. Can you give me an example please, I''m not that good with queries. Cheers Alex On Apr 15, 6:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 15, 8:44 am, Alex Djioev <dji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > @group_documents > > GroupDocument.find_all_by_group_id(params[:group_id]).paginate :page > > => params[:page], :per_page => 10, :order => ''?'' > > > Problem is with order. I want to return @group_documents collection > > ordered by document.title. Something like > > :order => ''group.title asc'' > > You need to join the groups table, then you''ll be able to order by > groups.title > > Fred > > > > > How is it possible? > > > Cheers Alex > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred, thanks for replay. Can you give me an example please, I''m not that good with queries. Cheers Alex On Apr 15, 6:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 15, 8:44 am, Alex Djioev <dji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > @group_documents > > GroupDocument.find_all_by_group_id(params[:group_id]).paginate :page > > => params[:page], :per_page => 10, :order => ''?'' > > > Problem is with order. I want to return @group_documents collection > > ordered by document.title. Something like > > :order => ''group.title asc'' > > You need to join the groups table, then you''ll be able to order by > groups.title > > Fred > > > > > How is it possible? > > > Cheers Alex > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alex Djioev wrote:> Hi Fred, > > thanks for replay. > > Can you give me an example please, I''m not that good with queries.An example won''t help you, then. What will help is reading about SQL joins and AR :joins.> > Cheers Alex > > On Apr 15, 6:34�pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.