This project is archived and is in readonly mode.

#6089 ✓resolved
Michał Łomnicki

Can't overwrite select for has_many through

Reported by Michał Łomnicki | November 30th, 2010 @ 12:25 PM

rails 3.0.3
ruby 1.9.2p53

Using'...') for has_many through appends columns instead of overwriting them. With rails 2.3 it works as intended

class Group < ActiveRecord::Base

class MessageGroup < ActiveRecord::Base
    belongs_to :message
    belongs_to :group

class Message < ActiveRecord::Base
   has_many :message_groups
   has_many :groups, :through => :message_groups
SELECT "groups".*, FROM "groups" INNER JOIN "message_groups" 
ON "groups".id = "message_groups".group_id WHERE (("message_groups".message_id = 8))

Correct query should look like

SELECT "groups".id FROM "groups" INNER JOIN "message_groups" ON 
"groups".id = "message_groups".group_id WHERE 
(("message_groups".message_id = 8))


Message.find(8).groups.all(:select => '')
produces the same wrong result

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=""></a>

Referenced by