2010-11-30 75 views
1

我有一個應用程序,我們只是從2.1.0升級到2.3.10。升級之後,以前工作的關聯擴展會導致失敗。這裏是關於模型的擴展代碼:關聯擴展不再適用於Rails 2.3.10

Class Classroom 

    has_many :registrations 

    has_many :students, :through => :registrations, :uniq => true do 
    def in_group(a_group) 
     if a_driver 
     scoped(:conditions => ['registrations.group_id = ?', a_group]) 
     else 
     in_no_group 
     end 
    end 

    def in_no_group 
     scoped(:conditions => 'registrations.group_id is null') 
    end 
    end 

end 

這是我的實際問題的簡化模型,但基本上我曾經是能夠做到

classroom.students.in_group(honor_students) 

此不再起作用,用下面的輸出:

classroom.students.in_group(honor_students) 
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'registrations.group_id' in 'where clause': SELECT * FROM `students` WHERE (registrations.group_id = 1234) 

當我剛剛搶學生名單中,SQL具有所有預期聯接語法有多數民衆贊成由以上版本丟失:

SELECT DISTINCT `students`.* FROM `students` INNER JOIN `registrations` ON `students`.id = `registrations`.student_id WHERE ((`registrations`.classroom_id = 9876)) 

爲什麼關聯擴展缺少所有的連接SQL?

回答