Welcome Guest | Login

Retrieving records in a specific order

This may seem like rails 101 - but this is driving me crazy...

I have 2 tables one is the parent one is the child structured like this:

companies
id
company_name

company_locations
id
company_id

I want to pull a list of specific company locations
when I list the data I can use..  :company_location.company.company_name - no problem
what I want to do is order the list by company_name.

I'm using pagination, heres the line of code:

@company_locations_pages, @company_locations = paginate :company_location, :per_page => 25, :conditions => 'host_flag = 1', :order => :company_location.company.company_name

the order clause is failing.  All the example of using :order look something like :order => 'field_name'  - but the field i want to use is not in the same table, so that isn't working

any help would be appreciated

2007-10-02 09:12 PM

EDIT:  Sorry, my mistake.  See William's post below.  

2007-10-02 11:43 PM

Regards,
Rahul
Rahul,

Did you mean to send that post to me?  It doesn't match my question???  This is the Rails coding forum and I am asking a coding question. There's no issue to recreate.

2007-10-03 04:04 AM

I see, you want to order the retrieval of records from a table by a column that doesn't exist in that table. I'm not sure if that is possible.    

Does company_location only 'has_one' company ?  That seems strange.  

While not exactly the same, could you get away with :order => 'company_id'?

Another thing you can do is sort the array of records after its retrieved.  

2007-10-03 04:56 AM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!