diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-05-29 06:56:46 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-05-29 06:57:55 +0900 |
commit | 56429f1e4dd6c3fd8fcdee4a7abc1eff1ea142ee (patch) | |
tree | f724b1735778654f531d58231f12783487d8a5cc /activerecord/test/models | |
parent | cfb493a3a311110a7b5bac6e0e74c6b5ead1040b (diff) | |
parent | d7a3f33dbd4726480fcbefc0c3c1270396f61fd2 (diff) | |
download | rails-56429f1e4dd6c3fd8fcdee4a7abc1eff1ea142ee.tar.gz rails-56429f1e4dd6c3fd8fcdee4a7abc1eff1ea142ee.tar.bz2 rails-56429f1e4dd6c3fd8fcdee4a7abc1eff1ea142ee.zip |
Merge pull request #32952 from mechanicles/32940-fix
Fix parent record should not get saved with duplicate children records
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/reply.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb index d1cee58788..d178413fd7 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 72699046f9..8368405cef 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 |