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”.
(I’m still getting the hijacked domain, so I hope that’s the right link)
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”.
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.