Hi,

I'm not sure 100% what you're trying to do but the presence of question_id
will not be there until the record has been saved. No?

And I'm not sure why you're doing this .... @grading =
@question.gradings.build(more_attributes)

Shouldn't you have done a build before presenting your form if you have
nested forms?

Maybe you could teach me something on what you're trying to do.

On 13 March 2010 16:54, Max Williams <[email protected]> wrote:

> Hi. I'm using rails 2.3.4 and have this association between two of my
> models.
>
> Question
>  has_many :gradings
>
> Grading
>  belongs_to :question
>
> Grading has this validation:
>  validates_presence_of :question_id
>
> And this validation test is stopping me from doingg this, which i would
> normally expect to work
>
> @question = Question.new(attributes)
> @grading = @question.gradings.build(more_attributes)
> @question.save #fails because grading has no question_id
>
> Now, i thought that this would work ok because (in my understanding) the
> question is saved and then it saves it's built associated objects.  How
> can i ensure this will work?  Do i need to drop the validation?  I'd
> rather not if possible.
>
> Grateful for any advice - max
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
100% naturally selected. 0% designed.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to