This project is archived and is in readonly mode.
Module table_name_prefix not respected for using set_table_name
-
jpfuentes2 (at gmail)
As far as 1 is concerned, it seems like it has something to do with autoloading models. When I do the following, the prefix is respected:
module Testing def self.table_name_prefix 'testing_' end end class Testing::Hello < ActiveRecord::Base end p Testing::Hello.table_name # testings_hellos Testing::Hello.reset_table_name p Testing::Hello.table_name # testing_hellos -
jpfuentes2 (at gmail)
- Tag changed from 3.0.0.rc, active_record, set_table_name, table_name_prefix to 3.0.0.rc, active_record, patch, set_table_name, table_name_prefix
Including a patch to fix #2 rake rails:freeze:edge on windows. set_table_name now accepts :prefix option like so
module Testing def self.table_name_prefix 'prefix_' end end class Testing::Hello < ActiveRecord::Base set_table_name :hiya, :prefix => true end p Testing::Hello.table_name # prefix_hiya -
Andrea Campi
+1
The attached patch doesn't apply (a whitespace at the end of the first comment line was removed), can you reroll it?
Apart from that, I verified the issue and your fix.As far as #1 Migrations will not run on a fresh database is concerned, I could not duplicate it, I could not reproduce it on either 3.0.0 or edge.
-
jpfuentes2 (at gmail)
(on Rails 3.0.1)
To be clear on #1 Migrations will not run on a fresh database the module's table_name_prefix is ignored because rails simply uses the module's name instead of the provided prefix:
module Testing def self.table_name_prefix 'custom_' end end class Testing::Hello < ActiveRecord::Base end p Testing::Hello.table_name # testing_hellosAlso, the patch applies just fine to 3.0.1 - should I try applying to edge?
git apply --stat patch activerecord/lib/active_record/base.rb | 12 ++++++++++-- activerecord/test/cases/modules_test.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) -
Andrea Campi
- Tag changed from 3.0.0.rc, active_record, patch, set_table_name, table_name_prefix to active_record, patch, rails3, set_table_name, table_name_prefix
Not sure what's the difference between me and you, but I still cannot reproduce on either 3.0.0 or 3.0.1 (or edge).
Copy and pasting your exact code gives me:ruby-1.9.2-p0 > module Testing ruby-1.9.2-p0 ?> def self.table_name_prefix ruby-1.9.2-p0 ?> 'custom_' ruby-1.9.2-p0 ?> end ruby-1.9.2-p0 ?> end => nil ruby-1.9.2-p0 > ruby-1.9.2-p0 > class Testing::Hello < ActiveRecord::Base ruby-1.9.2-p0 ?> end => nil ruby-1.9.2-p0 > ruby-1.9.2-p0 > p Testing::Hello.table_name # testing_hellos "custom_hellos" => "custom_hellos"Regarding the patch, yes please, it should go to edge (master) first.
-
jpfuentes2 (at gmail)
Here's the new patch applied to edge (master). You are right about the 1st case, it was not working in rails 3 pre, but is working now with 3.0.0 and 3.0.1.
-
Paul Eipper
I believe the :prefix option should be true by default for set_table_name
-
rails
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
