This project is archived and is in readonly mode.

#4269 ✓invalid
Martin Plöger

build through an association does not set the back-reference in Rails 3.0.0

Reported by Martin Plöger | March 25th, 2010 @ 09:46 PM

When I call the #build-method on an association the reference back (belongs_to) in the newly created instance is still nil.

@active_record_model.other_models.build.active_record_model # => nil

This makes it difficult when there are validations on the built object like 'validates_presence_of :active_record_model'.
These fail it this scenario:

@active_record_model.other_models.build

@active_record_model.save # => false

You have to use a workaround like that:

@active_record_model.other_models.build :active_record_model => @active_record_model

@active_record_model.save # => true

Comments and changes to this ticket

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

Pages