On 21 April 2010 12:10, DanC <d.m.coleg...@durham.ac.uk> wrote: > @topics = Topic.find(:all, :conditions => ["forum_id = ?", > @forum.id], :order => "total_replies DESC") > > but I get the error Mcolumn "total_replies" does not exist > > I know the column doesn't exist, but the question is, how can I get > the 'total_replies' to behave as a column.
You can't - it's a method on a model, and the DB knows nothing about it. But you can add a column that keeps the value of associated replies and then the query will work. Rails will do this for you with a "counter_cache". http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html (I'm still getting the hijacked domain, so I hope that's the right link) -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.