Hi all,
Section
3.9 presence of the
Active Record Validations and Callbacks guide states that
If you want to be sure that an association is present, you’ll need to test whether the foreign key used to map the association is present, and not the associated object itself.
class LineItem < ActiveRecord::Base
belongs_to :order
validates :order_id, :presence => true
end
However, after a few tests, I now think this is not so. It seems that you may indeed validate de presence of an instance at the opposite end of an association, and that you may do this from either end of the association. Am I wrong? The
Rails documentation does not help in this case.
Regards,
Manuel