Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Incorrect migrations when using pluralize_table_names

#767

This happens both with the latest (2.1) gem version and the latest git version.

environment.rb:

config.activerecord.pluralizetable_names = false

./script/generate migration fruits/delicious/apple

will produce file: 20080806203144createfruitsdeliciousapples

class CreateFruitsDeliciousApples < ActiveRecord::Migration def self.up

create_table :fruits/delicious_apple do |t|

  t.timestamps
end

end

def self.down

drop_table :fruits/delicious_apple

end end

Fixes needed: 1.File name and class name should be singular. 2.:fruits/deliciousapple should be :fruitsdelicious_apple

Reported by JS · August 6th, 2008 @ 09:37 PM

State: resolved
Milestone: 2.3.4
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. JS
    JS
    • Tag changed from generators, migrations to generators, migrations, patch

    FIX

    generator.rb lines 237:

    This @tablename = @classnesting.underscore << "" << @tablename

    Should be @tablename = @classnesting.gsub("::", "").gsub("/", "").underscore << "" << @tablename

    August 6th, 2008 @ 10:06 PM

  2. JS
    JS

    I'm sorry, the file name is railties/lib/rails_generator/base.rb

    This does not fix the wrong filename.

    August 6th, 2008 @ 10:12 PM

  3. JS
  4. JS
    JS
    • Tag changed from generators, migrations, patch to bug, generators, migrations, patch

    I attached fixed railties/lib/rails_generator/base.rb

    August 6th, 2008 @ 10:20 PM

  5. Pratik
    Pratik
    • State changed from new to incomplete

    Could you please upload a patch w/tests as described at http://rails.lighthouseapp.com/p...

    Thanks.

    August 22nd, 2008 @ 03:19 AM

  6. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from bug, generators, migrations, patch to bug, bugmash, generators, migrations, patch

    August 3rd, 2009 @ 03:08 PM

  7. Peer Allan
    Peer Allan

    Verified in 2.3-stable

    To replicate:
    - generated new app - add "ActiveRecord::Base.pluralize_table_names = false" to environment.rb - in terminal, $ script/generate model Fruit::Apple::Fuji - results in migration file: 2009xxxxxxx_create_fruit_apple_fujis.rb - class name in the file is also pluralized - create_table is invalid

    The table name in the migration is invalid regardless of the pluralization setting when there is more than one namespace associated to the model.

    The fix in the attached base.rb file is valid. Attempting to create a patch and tests, but having trouble finding the generator tests.

    August 9th, 2009 @ 05:11 AM

  8. Hugo Peixoto
    Hugo Peixoto

    verified in master.
    There were no tests whatsoever related to nested namespaced models generation.
    I've attached a patch which adds a substancial amount of test cases, as well as a fix for both bugs reported here.

    It doesn't work on 2-3-stable, due to all the files moving around in the railties. The tests could probably be used in 2-3-stable, though.

    August 9th, 2009 @ 10:30 AM

  9. Repository
    Repository
    • State changed from incomplete to committed

    (from [22b38c18c61a18babd671b973e804e054ba795d4]) Fixed generating a namespaced model with table pluralization turned off. Add tests for namespaced model generation.

    [#767 Incorrect migrations when using pluralize_table_names state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/22b38c18c61a18babd671b973e804e...

    August 9th, 2009 @ 10:41 AM

  10. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Jeremy Kemper
    • State changed from committed to incomplete
    • Milestone changed from 2.x to 2.3.4

    Now targeting a backport to 2.3.

    August 9th, 2009 @ 10:43 AM

  11. Hugo Peixoto
    Hugo Peixoto
    • Assigned user cleared.

    I've attached a patch which works in 2-3-stable, and contains the same features as the master patch that I've added before.

    August 9th, 2009 @ 11:29 AM

  12. Hugo Peixoto
    Hugo Peixoto
    • Assigned user set to Jeremy Kemper

    August 9th, 2009 @ 11:36 AM

  13. Jatinder Singh
    Jatinder Singh

    +1 verified, very nice work on tests.

    Applying the 2-3-stable patch gives me trailing whitespace errors though.

    August 9th, 2009 @ 12:15 PM

  14. José Valim
    José Valim
    • State changed from incomplete to resolved
    • Tag changed from bug, bugmash, generators, migrations, patch to bug, generators, migrations, patch

    August 9th, 2009 @ 04:00 PM