This project is archived and is in readonly mode.
[PATCH] ActiveRecord::Base class_name weirdness
Reported by Eadz | June 10th, 2008 @ 03:51 AM
class_name should return the class name or be called something else.
## Rails IRB Session, Rails 2.1
class DummyOne < ActiveRecord::Base
end
>> DummyOne.class_name
=> "DummyOne"
class DummyTwo < ActiveRecord::Base
set_table_name "dt"
end
>> DummyTwo.class_name
=> "Dt" ##
Comments and changes to this ticket
-
Cheah Chu Yeow June 23rd, 2008 @ 04:32 PM
Hmm, you can actually simply use Module#name:
DummyTwo.name
AR::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 June 27th, 2008 @ 01:09 AM
- 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 September 18th, 2008 @ 08:02 AM
- 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 December 19th, 2008 @ 03:49 PM
- Assigned user set to Tarmo Tänav
- State changed from new to incomplete
Need to deprecate the method too. Patch/Commit please :)
-
Eadz March 8th, 2009 @ 12:37 AM
- Tag changed from activerecord, tiny to 2.3.0, activerecord, tiny
Is this going to be fixed in 2.3?
-
Eadz February 8th, 2010 @ 01:57 AM
- 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 June 29th, 2010 @ 01:13 PM
- Assigned user changed from Tarmo Tänav to José Valim
- Importance changed from to
The
ActiveSupport::Deprecation
has 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 June 29th, 2010 @ 01:14 PM
The
ActiveSupport::Deprecation
has 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. -
José Valim June 29th, 2010 @ 01:42 PM
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 June 29th, 2010 @ 03:56 PM
Sure, I've made two patches: One that applies to
master
which simply removes the method and the corresponding test, and one that applies to2-3-stable
that issues a deprecation warning using thewarn
method and silences the deprecation warning in the test. -
David Trasbo June 29th, 2010 @ 03:56 PM
- no changes were found...
-
Repository June 29th, 2010 @ 04:55 PM
- State changed from incomplete to committed
(from [ac42e6951f0feb1a9890a3bbf5ebad87ebec08cc]) Deprecate ActiveRecord::Base#class_name [#379 state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/ac42e6951f0feb1a9890a3bbf5ebad... -
Repository June 29th, 2010 @ 04:58 PM
(from [735a4db6854e73e871e6b01ec003f0670cc5ee14]) Remove ActiveRecord::Base#class_name [#379 state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/735a4db6854e73e871e6b01ec003f0...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 379 [PATCH] ActiveRecord::Base class_name weirdness (from [ac42e6951f0feb1a9890a3bbf5ebad87ebec08cc]) Depreca...
- 379 [PATCH] ActiveRecord::Base class_name weirdness (from [735a4db6854e73e871e6b01ec003f0670cc5ee14]) Remove ...