This project is archived and is in readonly mode.

#5118 ✓resolved

Not saved children does not have parent object in has many association

Reported by Staszek | July 15th, 2010 @ 10:58 AM

We have got 2 objects in has_many relation

class User
 has_many :movies
class Movie
 belongs_to :user

If you create a parent object and the children then you have not access to parent object from children until you saved it.

user =
movie =
user.movies << movie

>> [#<Movie id: nil>]
>> nil

In my opinion children should always have information about its parent. It can be usefull if you need this information to prepare object before saving(or in validations).

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=""></a>