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?