This project is archived and is in readonly mode.

#4497 ✓duplicate
dlikhten

ActiveRecord associations .build does not set associations.

Reported by dlikhten | April 28th, 2010 @ 08:01 PM

object2 = object1.object2s.build

When the above code executes, the expected behavior is

object2.object1 == object1

however the actual behavior is

object2.object1 == nil

The workaround is

object2 = object1.object2s.build
object2.object1 = object1

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

Referenced by

Pages