We have objects that we want to represent in stacks (think of stacking items in an MMO). There will be duplicate rows.
Let's say our owned_objects table looks like this.
user_id | object_id
1 | 27
1 | 27
3 | 46
3 | 46
5 | 59
I want the query to do
SELECT
user_id,
object_id,
count(*) AS count
FROM owned_objects
GROUP BY
user_id,
object_id;
And return either the 3 distinct OwnedObject
s (or even just getting the distinct Object
s would work too) and a count associated with it.
I know this is possible with SQLAlchemy, but can you do it with ActiveRecord?