Re: validates_associated trouble

Mark Reginald James
Wed, 21 Feb 2007 13:54:14 -0000

>> Use validates_presence_of instead of validates_associated.
>
> the problem is that in some cases an Animals has not father or mother,
> then how can i do it??

This should allow clones if your foreign_keys are default NULL:

validates_presence_of :sire, :if => Proc { |animal| animal.sire_id }
validates_presence_of :dam,  :if => Proc { |animal| animal.dam_id  }

If instead they''re default 0, the condition becomes

    animal.sire_id > 0

etc.