Has_and_belongs_to_many :delete_sql not works?


#1

Hi all,

I have a has_and_belongs_to_many association, and define the delete_sql
myself.

Class A
has_and_belongs_to_many: b,
: delete_sql => ‘…’
end

Supposedly when A is destroy, the association record should be delete by
the delete_sql I define. But it seems that the delete sql will not be
overwritten.
Anybody works on this? Or I misunderstand the spec. ?

I checked the source code

activerecord-1.13.0/lib/active_record

def has_and_belongs_to_many(…


before_destroy_sql = “DELETE FROM #{options[:join_table]} WHERE
#{association_class_primary_key_name} = \#{self.quoted_id}”
module_eval(%{before_destroy
“self.connection.delete(%{#{before_destroy_sql}})”})

"


end

It seems that the :delete_sql option is never taken?

Gary