Skip to content

Commit

Permalink
Merge pull request #560 from guilleiguaran/fix_pluralize_table_names_…
Browse files Browse the repository at this point in the history
…false

Fixing has_many when ActiveRecord::Base.pluralize_table_names is false
  • Loading branch information
jonleighton committed May 16, 2011
2 parents bf5e4b4 + ecbde46 commit 2033ff8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Expand Up @@ -50,7 +50,7 @@ def aliased_name_for(table_name, aliased_name = nil)
end

def pluralize(table_name)
ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s
end

private
Expand Down
11 changes: 11 additions & 0 deletions activerecord/test/cases/associations/join_model_test.rb
Expand Up @@ -13,6 +13,8 @@
require 'models/edge'
require 'models/book'
require 'models/citation'
require 'models/aircraft'
require 'models/engine'

class AssociationsJoinModelTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false unless supports_savepoints?
Expand Down Expand Up @@ -704,6 +706,15 @@ def test_has_many_through_goes_through_all_sti_classes
assert_equal [9, 10, new_comment.id], authors(:david).sti_post_comments.map(&:id).sort
end

def test_has_many_with_pluralize_table_names_false
engine = Engine.create(:car_id => 1)
Aircraft.pluralize_table_names = false
aircraft = Aircraft.create!(:name => "Airbus 380", :id => 1)
assert_equal aircraft.engines, [engine]
ensure
ActiveRecord::Base.pluralize_table_names = true
end

private
# create dynamic Post models to allow different dependency options
def find_post_with_dependency(post_id, association, association_name, dependency)
Expand Down
3 changes: 3 additions & 0 deletions activerecord/test/models/aircraft.rb
@@ -0,0 +1,3 @@
class Aircraft < ActiveRecord::Base
has_many :engines, :foreign_key => "car_id"
end
4 changes: 4 additions & 0 deletions activerecord/test/schema/schema.rb
Expand Up @@ -40,6 +40,10 @@ def create_table(*args, &block)
t.references :account
end

create_table :aircraft, :force => true do |t|
t.string :name
end

create_table :audit_logs, :force => true do |t|
t.column :message, :string, :null=>false
t.column :developer_id, :integer, :null=>false
Expand Down

3 comments on commit 2033ff8

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, this broke active record test suite. Could you please take a look?

@jonleighton
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim As we discussed the tests are looking okay for me (I ran rake isolated_test_mysql successfully). I haven't been able to try oracle because my install is fucked (I run it rarely and have upgraded my OS since last time). I also have very little time in the next few days. If this is a blocker for the RC then I suggest a revert for now, but I'll let you decide.

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries man! Better to just ping oracle guys to take a look into? Maybe it would be easy to @tenderlove to do it?

Please sign in to comment.