How do you create a dynamic where clause for a custom SQL query in rails?

We need to do a count with a double group by, which to my knowledge is not supported by ActiveRecord in Rails 2.3, so we're doing a custom SQL query, something like:

ActiveRecord::Base.connection.execute("select COUNT(*), author_id, call_type_id from signup_calls group by author_id, call_type_id")

However, we also need to filter the signup calls being counted by three user selected filters, which need to be included in the where clause.

Is there someway I can use the ActiveRecord helpers to help generate the where clause. If not, what's the best way to go about it?


You can do'count(*) as signup_count, author_id, call_type_id').group('author_id, call_type_id')

Then just chain where clauses afterwards.

Need Your Help

BMT EJB How to use the UserTransaction

java transactions jboss ejb jta

I'm trying to create an example of BMT EJB and control the transaction manualy but when try to run I got an NullException and I don't kno what I'm doing wrong.

C# Dictionary as a ListBox.DataSource

c# dictionary listbox datasource

I am trying to bind a dictionary as a DataSource to a ListBox. The solution in How to bind a dicationary to a ListBox in winforms will not work for me because my dictionary is a class-level variab...