[Rails] sorting attribute in list from foreign table

Gilles
Tue, 15 Aug 2006 21:19:23 -0000

Hello, I currently have two tables.

table_a (
  id
  table_b_id
  other_attrs
)

table b (
  id
  name
)

So table A holds an id from table B. During the listing of tuples in
table A, it lists table A''s attributes. In place of the table B id, I
check the id, and instead display the name corresponding to that id. Now
I want to be able to sort the listing of tuples in table A by the names
of table B. Here is some code to hopefully help you understand more
clearly what I''m trying to do.

    sort = case @params[:sort]
           when "last inserted"  then "id DESC"
           when "name"  then "table_b.name" # <---- does
not work
           end

    @table_a_pages, @table_as = paginate :table_a, :order => sort,
:per_page => 10

At the noted line, I am unable to use table_b.name to sort the list. Any
suggestions on how to solve this? Thanks!

-Gilles

--
Posted via http://www.ruby-forum.com/.