This project is archived and is in readonly mode.
has_many :through associations are created with .create! even if the parent is created with .create
-
rails
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
-
ronin-23439 (at lighthouseapp)
+1 this problem also exists when using the << method.
-
Erik Michaels-Ober
+1
This is causing an issue in RailsAdmin.
-
hemant
- Tag changed from activerecord, has_many_through, validation to :confirm, activerecord, has_many_through, testcase, validation
+1 The issue exists in edge rails and all previous versions.
I've attached a failing test.I see that in activerecord/lib/active_record/associations/has_many_through_association.rb, line 36
def insert_record(record, validate = true) ensure_not_nested return if record.new_record? && !record.save(:validate => validate) through_record(record).save! update_counter(1) record endthrough_record(join record) is explicitly being saved with save! which will always result in an exception if record not saved.
Shouldn't there be a way we can track if we need to use a bang operator here or not and based on that either add error to the parent record or raise exception.
