Dites s'il y a une table avec des champsComment Ruby on Rails gère-t-il "Select count (*) from products group by category"?
Products
--------
ID
CategoryID
Name
Price
... etc
Comment Ruby on Rails donner une table qui retourne
select count(*) from products group by categoryID
qui est de montrer combien de produits dans chaque catégorie? Comment sera le résultat, par opposition à Products.find(:all)
qui est un tableau d'objets de produit?
Comme une opération plus avancée, que diriez-vous
select count(*) from products p inner join category c on p.categoryID = c.ID
group by categoryID
et
select average(price) from products p inner join category c on p.categoryID = c.ID
group by categoryID
?