When creating a record off nesting, why isn't the parent id being added to the child?
Given the following
Thread
belongs_to :user
User
has_many :threads, :through => :thread_members
When I do:
@user.threads.create(:title => "hello")
In my Thread model I have a before_create, and in that method I and Rails.logger.info self.inspect which outputs:
#<Thread id: nil, user_id: nil, title: "hello" ...
Why is user_id not being assigned? Than开发者_如何学运维ks
Check that the @user is already saved, the parent records must be saved before the children get their foreign keys set. Please show the controller code that loads that @user object.
精彩评论