Permalink
Browse files

support objects with blank string primary keys

  • Loading branch information...
1 parent 6256734 commit 460eb83de0579c36d96410e48a1385987ad0020c @tenderlove tenderlove committed Sep 18, 2013
Showing with 7 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/core.rb
  2. +6 −0 activerecord/test/cases/base_test.rb
@@ -284,7 +284,7 @@ def encode_with(coder)
def ==(comparison_object)
super ||
comparison_object.instance_of?(self.class) &&
- id.present? &&
+ id &&
@avsej

avsej Sep 24, 2013

so two objects with nil ids supposed to be different?

@avsej

avsej Sep 24, 2013

Ah, I see. Two not committed object might carry different sets of attributes. Nevermind

comparison_object.id == id
end
alias :eql? :==
@@ -566,6 +566,12 @@ def test_create_without_prepared_statement
assert_equal topic, Topic.find(topic.id)
end
+ def test_blank_ids
+ one = Subscriber.new(:id => '')
+ two = Subscriber.new(:id => '')
+ assert_equal one, two
+ end
+
def test_comparison_with_different_objects
topic = Topic.create
category = Category.create(:name => "comparison")

0 comments on commit 460eb83

Please sign in to comment.