From d7a3f33dbd4726480fcbefc0c3c1270396f61fd2 Mon Sep 17 00:00:00 2001 From: Santosh Wadghule Date: Tue, 22 May 2018 19:04:24 +0530 Subject: Fix parent record should not get saved with duplicate children records - Fixes #32940 --- activerecord/test/models/reply.rb | 5 +++++ activerecord/test/models/topic.rb | 1 + 2 files changed, 6 insertions(+) (limited to 'activerecord/test/models') 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 -- cgit v1.2.3