ActiveRecord: Do I need both belongs_to and has_one

后端 未结 2 1278
灰色年华
灰色年华 2021-02-20 00:04

I have 2 models, namely user and userprofile. There is a one-to-one relationship between user and userprofile.



        
2条回答
  •  不要未来只要你来
    2021-02-20 00:41

    Having just a belongs_to relationship between userprofiles and user does default to has_one. However, it would be wise (Rails-proper) to specify the association on both models.

    After all, if you wanted a has_many association (etc) you would want to specify that.

    Check out http://guides.rubyonrails.org/association_basics.html for more info

提交回复
热议问题