开发者

Association Extensions no longer working in Rails 2.3.10

I have an app that we just upgrade from 2.1.0 to 2.3.10. After the upgrade, an Association Extension that previously worked causes a failure. Here is the code on the model for the extension:

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开发者_StackOverflow中文版_id = ?', a_group])
      else
        in_no_group
      end
    end

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

end

This is a simplified model of my actual issue, but basically I used to be able to do

classroom.students.in_group(honor_students)

This no longer works, with the following output:

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)

When I just grab the list of students, the SQL has all the expected join syntax there thats missing from the above version:

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

Why is the association extension missing all the join SQL?


use this Rails 2.3: How to turn this SQL statement into a named_scope on students instead of nesting it in association

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜