开发者

Rails 3: Skip validation for associated model

开发者 https://www.devze.com 2023-04-12 17:12 出处:网络
It seems that in rails 3 (version 3.0.7) validates_associated is enabled by default (and as a result it is deprecated).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号