Forum: Ruby on Rails validates_presence_of fields. in parent ok, but how in child

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
dweinand (Guest)
on 2007-01-27 03:35
(Received via mailing list)
i have the problem that my child class fileds aren't validated on
saving the
parent. working with parent and child works without problems.
if all fields are filled correctly everything is saved as expected.
but missing fields in the child arent added to the errors.
following short sample shows what i try:

class Parent < ActiveRecord::Base
  has_one  :children
  validates_presence_of :parent_name

  def init!

class Children < ActiveRecord::Base
  belongs_to  :parent
  validates_presence_of children_name

@parent = session[:parent] ||=

the absence of parent_name will be correctly shown @parent.errors
but i cant find the absence of children_name isnt it validated?

if parent_name is set and children name is nullable in DB
everything will be saved without validating.

i think im missing something important at this pont.

any help?
This topic is locked and can not be replied to.