Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 Rails 应用程序中,我有一个组织模型,其中引用了一个用户,我希望能够通过 organization_instance.adminstrator 访问它。我不确定如何使用belongs_to 方法来完成此操作。
没关系。正确的解决方案(正如我发现的那样)是执行以下操作:
belongs_to :administrator, :class_name => "User"
有趣的是阅读文档可以为您做什么:D
但是,这提出了一个新问题,该问题在文档中并不直接明显:如何为此生成迁移?将
t.references :user
或者
t.references :administrator
是正确的方法?