This project is archived and is in readonly mode.
[PATCH] ActiveRecord::Base class_name weirdness
-
Cheah Chu Yeow
Hmm, you can actually simply use Module#name:
DummyTwo.nameAR::Base#class_name is actually documented like so:
"Turns the +table_name+ back into a class name following the reverse rules of +table_name+."
So while the method name may be misleading, I don't think it was intended to be used the way you described.
-
Eadz
- Tag set to activerecord, tiny
In the context of "Turns the +table_name+ back into a class name" what exactly is a "class name" if not the name of the class?
-
Tarmo Tänav
- Tag changed from activerecord, tiny to activerecord, tiny
Perhaps the method should be removed?, nothing in AR seems to depend on it (the only test that breaks when this method is broken is the test for this method) and as is clear from this ticket it is misleading and, at least to me, seems practically useless.
-
Pratik
- Assigned user set to Tarmo Tänav
- State changed from new to incomplete
Need to deprecate the method too. Patch/Commit please :)
-
Eadz
- Tag changed from activerecord, tiny to 2.3.0, activerecord, tiny
Is this going to be fixed in 2.3?
-
Eadz
- Tag changed from 2.3.0, activerecord, tiny to 2.3.0, 3.0pre, activerecord, cleanup, tiny
- Title changed from ActiveRecord::Base class_name weirdness to [PATCH] ActiveRecord::Base class_name weirdness
This bug/feature is still in rails 3.0-pre.
Loading development environment (Rails 3.0.0.beta)
Site.class_name => "Site"
class Site < ActiveRecord::Base set_table_name "my_site_table" end => nil Site.class_name => "MySiteTable"
And it is still the case that when this method is removed completely from activerecord/base.rb, the only test that fails is the one for the method itself.
Additionally, the method might not do as advertised, its description states :
"Turns the +table_name+ back into a class name following the reverse rules of +table_name+."
However, #table_name has been updated to check for parent's tables to do with STI. I'm not sure if this method would work with STI in its current state.
I've attached a patch which deprecates class_name, and removes the test for it ( else you'll get deprecation warnings in your tests )
-
David Trasbo
- Assigned user changed from Tarmo Tänav to José Valim
- Importance changed from to
The
ActiveSupport::Deprecationhas native support for deprecating methods. I've attached a patch that makes use of that. Also, I propose not removing the test until the method itself is removed. -
David Trasbo
The
ActiveSupport::Deprecationhas native support for deprecating methods. I've attached a patch that makes use of that. Also, I propose not removing the test until the method itself is removed. -
David Trasbo
Ignore
2901.diff. It's a patch for another ticket. :) -
José Valim
David, we can simply remove the method in Rails 3.0 and deprecate it only in 2-3-stable. Besides, we use only the ActiveSupport::Deprecation.warn pattern inside Rails. Could you please use it as well?
-
David Trasbo
Sure, I've made two patches: One that applies to
masterwhich simply removes the method and the corresponding test, and one that applies to2-3-stablethat issues a deprecation warning using thewarnmethod and silences the deprecation warning in the test. -
Repository
- State changed from incomplete to committed
(from [ac42e6951f0feb1a9890a3bbf5ebad87ebec08cc]) Deprecate ActiveRecord::Base#class_name [#379 [PATCH] ActiveRecord::Base class_name weirdness state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/ac42e6951f0feb1a9890a3bbf5ebad... -
Repository
(from [735a4db6854e73e871e6b01ec003f0670cc5ee14]) Remove ActiveRecord::Base#class_name [#379 [PATCH] ActiveRecord::Base class_name weirdness state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/735a4db6854e73e871e6b01ec003f0...
