Forum: Ruby on Rails has_and_belongs_to_many :delete_sql not works?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
garychlin (Guest)
on 2005-11-15 19:45
(Received via mailing list)
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
This topic is locked and can not be replied to.