I’ve been searching Google and no one has come across this problem yet. I am writing a has_and_belongs_to_many custom sql, and it won’t let me specify :delete_sql. Here’s my code so far:
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
I found the documentation on delete_sql for has_and_belongs_to_many… I think I’m following them exactly, but I am getting the following error when I try to use this class:
Foo.new
But it’s raising the following error:
ArgumentError: Unknown key(s): delete_sql
I don’t think it makes a difference, but I’m using Rails v3.0.5
Should I fill out a bug report or am I missing the obvious?
So, it turns out that I just lie to rails and tell it that its a
has_and_belongs_to_manyassociation…