This project is archived and is in readonly mode.
association_collection#create acts as association_collection#create!
Reported by stefanpenner | July 21st, 2009 @ 09:13 PM
ActiveRecord has_many :through's association_collection#create seems to act as association_collection#create!, raising errors instead of merely building the AR object instance with the appropriate errors.
#example
http://github.com/stefanpenner/association_collection_create_bug/
Example
#results in an error being raised.
group.users.create(..with..invalid..user..attributes..)
Specs
#Failing specs are included.
rake
Workaround
#Hackish Workaround.
@user = group.users.create(..with..invalid..user..attributes..) rescue User.build(..with..invalid..user..attributes..)
Comments and changes to this ticket
-
Michael Koziarski August 3rd, 2009 @ 06:17 AM
- Tag changed from activerecord to activerecord, bugmash
-
railsbob August 8th, 2009 @ 12:21 PM
Verified
I was able to reproduce this error with the help of mentioned example.
-
José Valim August 8th, 2009 @ 08:16 PM
Just to add a notice, I asked @railsbob to rebase the patch and improve test coverage. Here is a example of tests for has_many: http://pastie.org/576732
-
railsbob August 8th, 2009 @ 09:04 PM
Sorry, please ignore the previous patch (whitespace error). This one applies cleanly.
-
railsbob August 8th, 2009 @ 11:48 PM
As discussed with lifo, the previous patch is modifying << method. I am attaching another patch, which removes << from create method.
-
Rizwan Reza August 8th, 2009 @ 11:54 PM
verified
+1 The patch works cleanly on master but does not in 2-3-stable.
-
Dan Croak August 10th, 2009 @ 02:18 AM
verified 2934_fixed.diff does not apply cleanly to 2-3-stable.
-
Dan Croak August 10th, 2009 @ 02:33 AM
I've attached a patch that works for 2-3-stable. It was modified from railsbob's 2934_fixed.diff patch for master. I don't think it is possible to have a single patch that will work for both, at least without serious refactoring of one of the tests.
-
Jeremy Kemper August 10th, 2009 @ 02:52 AM
- State changed from new to committed
- Tag changed from activerecord, bugmash to activerecord
- Milestone cleared.
-
Repository August 10th, 2009 @ 02:52 AM
(from [33c054d7e04672201e120a0f8da38166650f3a94]) has_many :through create should not raise validation errors
[#2934 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/33c054d7e04672201e120a0f8da381... -
Repository August 10th, 2009 @ 02:52 AM
(from [e06a0b03c8ba29f4b05a35560645814ac88aefbe]) has_many :through create should not raise validation errors
[#2934 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/e06a0b03c8ba29f4b05a3556064581...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 2934 association_collection#create acts as association_collection#create! [#2934 state:committed]
- 2934 association_collection#create acts as association_collection#create! [#2934 state:committed]