alexd
1
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
alexd
2
On Apr 15, 8:44 am, Alex D. [email protected] 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
alexd
3
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 C. [email protected]
alexd
4
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 C. [email protected]
alexd
5
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 C. [email protected]
alexd
6
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 C. [email protected]
alexd
7
Alex D. 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 C. [email protected]
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]