开发者

Rails and mongoid: Validation is called on the referenced document upon saving/updating the referrer document?

I have a model Tracker that references_many Users. Everything works fine, but for some business reasons, sometimes my Users model are in a situation were often they fails the validation rules (on purpose).

The problem is that I still need to update my Trackers in parallel of that. And to my surprise saving the tracker will trigger the validation rules for my User model as well... and obviously then the saving of the tracker fails.

I could save my tracker with save :validate => false, but I don't want to do that I have specific validation rules on the Tracker itself that I want to be respected. I also tried to play with deactivating callbacks but could not get it to work...

H开发者_开发百科elp please !

Alex


Ok, finally figured it out:

references_many :referees, :class_name => "User", :validate => false

This will do the trick !

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜