Skip to content

Commit

Permalink
if there is no base name, we cannot determine a primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Dec 21, 2010
1 parent 0516806 commit 099a210
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def reset_primary_key #:nodoc:
end

def get_primary_key(base_name) #:nodoc:
return unless base_name

case primary_key_prefix_type
when :table_name
base_name.to_s.foreign_key(false)
base_name.foreign_key(false)
when :table_name_with_underscore
base_name.to_s.foreign_key
base_name.foreign_key
else
'id'
end
Expand Down
2 changes: 2 additions & 0 deletions activerecord/test/cases/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ def test_define_attr_method_with_value

def test_define_attr_method_with_block
k = Class.new( ActiveRecord::Base )
k.primary_key = "id"
k.send(:define_attr_method, :primary_key) { "sys_" + original_primary_key }
assert_equal "sys_id", k.primary_key
end
Expand Down Expand Up @@ -1109,6 +1110,7 @@ def test_set_primary_key_with_value

def test_set_primary_key_with_block
k = Class.new( ActiveRecord::Base )
k.primary_key = 'id'
k.set_primary_key { "sys_" + original_primary_key }
assert_equal "sys_id", k.primary_key
end
Expand Down

0 comments on commit 099a210

Please sign in to comment.