ragar90
ragar90

Reputation: 98

Association in Ruby on Rails

I have a question with Rails 3.1 associations. When you have a one-to-many association you put the has_many operators on the many side of the relationship and the usual example does something like this:

class Order < ActiveRecord::Base
  belongs_to :customer
end

class Customer < ActiveRecord::Base
 has_many :orders
end

My question is how should I do this if the class name is Orders? Should I put has_many :orders or should I always name my models using singular nouns?

Upvotes: 0

Views: 105

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 97004

Rails convention states that model names should always be singular, so you should never have a model class named Orders; it would probably just be Order.

Upvotes: 4

Related Questions