In Rails 2.3.8 there is a class method ActiveRecord::Base.count_by_sql which allows to perform custom SELECT count(*) .... Is it save to execute customized SELECT sum(...) ... query with this method? If not, what should be done to execute such a query? Is ActiveRecord::Base.connection.execute the only option?
Thanks.
EDIT: Query I want to perform has another query nested. That’s why I believe methods from ActiveRecord::Calculations are not sufficient.
select_valuefromActiveRecord::ConnectionAdapters::DatabaseStatementsmodule is the answer. It returns the value present in the first column of the first row returned by query.select_valuereturnsString, so conversion may be necessary.Example: