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
. Both are references to the User
model. I tried this:
rails generate model Message sender:references recipient:references
Rails generated this:
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
. I'm running Ruby 2.0.0 and Rails 4.0.2. Any help is highly appreciated. Please ask me if you need more information about my problem.
You can specify the class name of the association, doc
class Message < ActiveRecord::Base
belongs_to :sender, class_name: 'User'
belongs_to :recipient, class_name: 'User'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With