[英]Ruby on Rails: two references with different name to the same model
My app has a model called User
(it includes the email adress, username..) I want to create a model Message
it should have two fields sender
and recipient
. 我的应用程序有一个名为
User
的模型(它包括电子邮件地址,用户名..)我想创建一个模型Message
它应该有两个字段sender
和recipient
。 Both are references to the User
model. 两者都是对
User
模型的引用。 I tried this: 我试过这个:
rails generate model Message sender:references recipient:references
Rails generated this: Rails生成了这个:
class Message < ActiveRecord::Base
belongs_to :sender
belongs_to :recipient
end
But I don't want two different models. 但我不想要两种不同的型号。 Both fields should reference to
User
. 这两个字段都应引用
User
。 I'm running Ruby 2.0.0 and Rails 4.0.2. 我正在运行Ruby 2.0.0和Rails 4.0.2。 Any help is highly appreciated.
任何帮助都非常感谢。 Please ask me if you need more information about my problem.
如果您需要有关我的问题的更多信息,请询问我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.