How do I do something like this in active query?
select product.*, count(product_id) AS product_counts
group by(product.*)
order by product_counts;
I tried this in active query:
Product.select("product fields, count(product_id) AS product_counts").group("product fields").order(product_counts)
The resultset i get back contains only the products that are sorted in the correct count order, but no count value. I did a .to_sql and it returns the correct sql.
How can I do this or something similar while being efficient on the db?
Another related question is, how do I do a .select("product.*)
or .group("product.*")
in active query? Right now I have to list every field out, eg. .group("product.id, product.name, product.price...etc")