paul h wrote: > Hi Max, > > Have you tried: > > @question = Question.create(attributes) > @grading = @question.gradings.build(more_attrs) > > Using create instead of new will save the Object to the DB first, and > hence: >
Hi Paul. Yes, i know that, thanks - in this situation i would do gradings.create rather than gradings.build. One of the advantages, though, of using build is that you can do it before the parent has been saved, and when the parent is saved it will save the child as well. In general, i try to stick to the standard controller code as much as possible, which means setting the child gradings through a set method which will be called by .update_attributes. This is a nice approach as it means no changes to the standard controller code is required. When i drop the validation on Grading#question_id (or Grading#question) then it works fine. My question was really about the behaviour of the unsaved child objects, and whether they 'know' they have a parent. It seems they don't. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.