It seems that in rails 3 (version 3.0.7) validates_associated is enabled by default (and as a result it is deprecated).
My model Payment has an associated model Reminder:
class Payment < ActiveRecord::Base
belongs_to :reminder
end
whenever I create a new payment, it also validates the associated remind开发者_如何学运维er. I want to skip this. Adding :validate => false to the relation didn't work. Any suggestions? And also if someone could tell about the changes in rails 3 w.r.t validates_associated, as I couldn't find it.
I see no reason why an association validation would be happening unless explicitly defined. Is there anything on your reminder that could be doing a check?
http://apidock.com/rails/v3.0.7/ActiveRecord/Associations/ClassMethods/belongs_to
http://apidock.com/rails/v3.0.7/ActiveRecord/Validations/ClassMethods/validates_associated
It isn't a validation issue, but I was updating my Reminder model after creating the Payment entry. That resulted in the validations for Reminder model being triggered.
Added a condition for that special case (where I wanted to skip the validation) to not update the reminder model.
Even though the answer is specific to my scenario, but adding as it may be of help to someone.
精彩评论