Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord associations .build does not set associations.

#4497

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

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Ryan Bigg
    Ryan Bigg

    Please create a failing test case for this issue in the form of a patch.

    April 29th, 2010 @ 12:50 AM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to duplicate

    Duplicate of #990 association#build inconsistency. Please apply the patch to this ticket.

    April 29th, 2010 @ 12:52 AM