In the docs it says I should validate the presence of the foreign key
and not the object itself. I did this and I still get the error when
both objects are new records. A very simple example:
class UserGroup < ActiveRecord::Base
has_many :users, :dependent => :destroy
end
class User < ActiveRecord::Base
belongs_to :user_group
validates_presence_of :user_group_id
end
user_group = UserGroup.new
user_group.users.build
user_group.save!
Tells me that users is invalid and it says that user group cant be
blank. In the docs it says if I do this I should not get this error. Is
this a new edition to ActiveRecord or something? I am using edge rails.
Thanks!