Reflections generate the default class_name for the associated object(s) from the association-name. This fails, however, when two models are in the same module and the association does not get the class_name set explicitly.
This results in a bug, when the :dependent flag is set to :delete_all (and presumably also for :destroy and :nullify). The generated before_destroy callbacks (in associations.rb, starting at line 1131) use reflection.class_name, which then cannot be found and results in an exception.
Some example code:
module AccessControl
class Account < ActiveRecord::Base
has_many :roles, :dependent => :delete_all
[...snip...]
end
class Role < ActiveRecord::Base
belongs_to :account
[...snip...]
end
end
account = AccessControl::Account.create!
account.roles.create!
account.destroy
The has_many association would generate the following callback code:
before_destroy { |record| Role.delete_all(%([...snip...])) }
Instead, it should be:
before_destroy { |record| AccessControl::Role.delete_all(%([...snip...])) }
I have attached a patch for this bug and added two test-cases, which pass the reflection tests using MySQL. Since this is not adapter-specific code, I do not expect problems on other databases.