aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorSantosh Wadghule <santosh.wadghule@gmail.com>2018-05-22 19:04:24 +0530
committerSantosh Wadghule <santosh.wadghule@gmail.com>2018-05-28 18:23:21 +0530
commitd7a3f33dbd4726480fcbefc0c3c1270396f61fd2 (patch)
treec7fef63458aafa3893a8819ab3c918a0f6bc64b1 /activerecord/test/models
parent2f76256127d35cfbfaadf162e4d8be2d0af4e453 (diff)
downloadrails-d7a3f33dbd4726480fcbefc0c3c1270396f61fd2.tar.gz
rails-d7a3f33dbd4726480fcbefc0c3c1270396f61fd2.tar.bz2
rails-d7a3f33dbd4726480fcbefc0c3c1270396f61fd2.zip
Fix parent record should not get saved with duplicate children records
- Fixes #32940
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/reply.rb5
-rw-r--r--activerecord/test/models/topic.rb1
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb
index bc829ec67f..312c8677c2 100644
--- a/activerecord/test/models/reply.rb
+++ b/activerecord/test/models/reply.rb
@@ -16,6 +16,11 @@ end
class SillyUniqueReply < UniqueReply
end
+class ValidateUniqueContentReply < Reply
+ belongs_to :topic, foreign_key: "parent_id"
+ validates :content, uniqueness: true
+end
+
class WrongReply < Reply
validate :errors_on_empty_content
validate :title_is_wrong_create, on: :create
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 2e386d7669..c6c9ccbc8d 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -47,6 +47,7 @@ class Topic < ActiveRecord::Base
has_many :unique_replies, dependent: :destroy, foreign_key: "parent_id"
has_many :silly_unique_replies, dependent: :destroy, foreign_key: "parent_id"
+ has_many :validate_unique_content_replies, dependent: :destroy, foreign_key: "parent_id"
serialize :content