开发者

Name a reference in ActiveRecord

开发者 https://www.devze.com 2022-12-17 08:34 出处:网络
in my rails app, I have an Organization model, wi开发者_StackOverflowth a reference to a User, which I want to be able to access via organization_instance.adminstrator. I\'m not sure how to accomplish

in my rails app, I have an Organization model, wi开发者_StackOverflowth a reference to a User, which I want to be able to access via organization_instance.adminstrator. I'm not sure how to accomplish this using the belongs_to method.


Nevermind. The proper solution (as I found it), is to do the following:

belongs_to :administrator, :class_name => "User"

interesting what reading the documentation can do for you :D

However, this poses a new question which is not directly apparent from the documentation: How do I generate the migration for this? Would

t.references :user

or

t.references :administrator

be the correct way?

0

精彩评论

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