This project is archived and is in readonly mode.

#5441 ✓resolved
oleg dashevskii

[PATCH] ActiveRecord::Calculations#count doesn't allow table names in column_name argument

Reported by oleg dashevskii | August 24th, 2010 @ 02:19 PM | in 3.0.2

I have the following code that works in 2.3.8

@dishes.count('order_items.id',
              :group => 'dishes.id',
              :joins => {:multi_dishes => { :menu_item => :order_items }})

@dishes is some Dish scope. This code counts how many times each dish appeared in orders.

When I try to run it under 3.0.0.rc2, it fails (@dishes = Dish):

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'dishes.order_items.id' in 'field list': SELECT COUNT(dishes.order_items.id)
AS count_order_items_id, dishes.id AS dishes_id FROM dishes
INNER JOIN multi_dishes ON multi_dishes.dish_id = dishes.id INNER JOIN menu_items ON menu_items.id = multi_dishes.menu_item_id
INNER JOIN order_items ON order_items.menu_item_id = menu_items.id GROUP BY dishes.id

The problem is apparent: unneeded 'dishes.' prepended to the column name.

I also tried to specify :select option, but it made no change.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages