Rails ArgumentError:未知密钥:delete_sql

时间:2011-03-04 01:40:46

标签: ruby-on-rails-3 activerecord

我一直在搜索谷歌,但还没有人遇到过这个问题。我正在编写has_and_belongs_to_many自定义sql,它不会让我指定:delete_sql。到目前为止,这是我的代码:

class Foo
  has_many :students,
           :class_name => 'User',
           :finder_sql => 'SELECT users.* FROM users, groups, students_groups WHERE users.id = students_groups.student_id AND students_groups.group_id = groups.id AND groups.course_period_id = #{id}',
           :delete_sql => 'DELETE FROM students_groups WHERE students_groups.student_id = #{record.id} AND students_groups.group_id IN (SELECT groups.id FROM groups WHERE groups.course_period_id = #{id})'
end

我发现the documentation on delete_sql for has_and_belongs_to_many ...我认为我正在完全关注它们,但是当我尝试使用这个类时,我收到以下错误:

Foo.new

但它引发了以下错误:

ArgumentError: Unknown key(s): delete_sql

我不认为它有所作为,但我使用的是Rails v3.0.5

我应该填写错误报告还是我错过了明显的错误报告?

1 个答案:

答案 0 :(得分:0)

所以,事实证明我只是骗铁路并告诉它它是一个has_and_belongs_to_many协会......