Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I do if I named a Model in Rails 3 plural?

I created a model called UserHasMessages based on some SO postings. I think this seems to be creating some challenges for me:

  • How do I reference it with has_many? Should I use has_many :user_has_messageses?

  • How do I do joins? I have tried User.joins(:user_has_messages) and it is sad :(

Question:

Should I somehow change the name to UserHasMessage, and if so, how?

If I keep as plural, how do I handle these cases?

like image 856
Satchel Avatar asked Nov 30 '25 01:11

Satchel


1 Answers

You can use the same syntax you use with legacy tables:

class OtherClass < ActiveRecord::Base
  has_many :user_has_messages, :class_name => 'UserHasMessages'
end
like image 125
tommasop Avatar answered Dec 02 '25 15:12

tommasop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!