validates_associated not checking existence of associations

前端 未结 2 736
攒了一身酷
攒了一身酷 2020-12-13 21:47

Can anyone figure out what\'s going on here? I was able to get my code to work the way I want it to, but I can\'t figure out why validates_associated isn\'t working as I ex

相关标签:
2条回答
  • 2020-12-13 22:16

    Man... all I got was that validates_presence_of is needed for this to work as you got from the API. Seem's overkill to be checking for association validness, but I'm a noob.

    0 讨论(0)
  • 2020-12-13 22:33

    validates_associated simply runs the validations that are specified within the associated object's class, it does nothing in regard to foreign keys.

    validates :user_id, :presence=>true ensures the presence of a user_id in your flag record, but that's all.

    validates :user, :presence=>true is used on the association itself and ensures that foreign keys are properly set up.

    0 讨论(0)
提交回复
热议问题