rubyonrailsin

A Ruby and Rails talk

Saturday, March 13, 2010


[Rails] validates_presence_of :parent_id stopping save

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

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

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive