Michael Pavling wrote:
> On 21 April 2010 12:10, DanC <[email protected]> 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 could also select it as an additional column (by getting it from the 
SQL count() function), although I don't know how well ActiveRecord would 
deal with that.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to