[Rails-core] #3005 - Prevent duplicate names (needs review for 1.1)
Francois Beausoleil
francois.beausoleil at gmail.com
Mon Feb 27 04:14:06 GMT 2006
Hi !
I was taking another look at http://dev.rubyonrails.org/ticket/3005
I reread the discussion we had here in late December:
http://thread.gmane.org/gmane.comp.lang.ruby.rails.core/41
The patch still applies cleanly. After removing the exceptions we had
talked about, now I have another problem:
$ rake test_mysql
(in D:/rails-trunk/activerecord)
...
Using native MySQL
./test/../lib/active_record/reflection.rb:61:in
`guard_against_already_used_method_name': `parent' is the name of an
existing method in TreeMixin. You will have to rename your
association. (ActiveRecord::Reflection::ReflectionNameAlreadyTaken)
from ./test/../lib/active_record/reflection.rb:16:in `create_reflection'
from ./test/../lib/active_record/associations.rb:917:in
`create_belongs_to_reflection'
from ./test/../lib/active_record/associations.rb:469:in `belongs_to'
from ./test/../lib/active_record/acts/tree.rb:47:in `acts_as_tree'
from ./test/fixtures/mixin.rb:6
from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require__'
from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
from ./test/../lib/../../activesupport/lib/active_support/dependencies.rb:149:in
`require'
from ./test/mixin_nested_set_test.rb:3
from C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5:in
`load'
from C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5
from C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5:in
`each'
from C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader.rb:5
rake aborted!
So now, we can't even create a parent method - it already exists:
# activesupport/lib/active_support/dependencies.rb:81
class Module #:nodoc:
# Rename the original handler so we can chain it to the new one
alias :rails_original_const_missing :const_missing
def parent
...
end
end
Boohoo !
I updated the patch, and here's the list of methods I guard against:
methods = active_record.instance_methods
methods += ActiveRecord::Base.methods
methods -= Object.methods
methods.uniq!
methods -= %w(name type)
See the initial thread on why we need to keep ActiveRecord::Base class
methods in the list.
I think this would be a good patch to include in 1.1.
Bye !
--
François Beausoleil
http://blog.teksol.info/
More information about the Rails-core
mailing list