Forum: Ruby on Rails Model associations

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Rick (Guest)
on 2005-11-19 20:22
How does Active Record determine what tables to use when you define an
association?  For example

  class Order < ActiveRecord::Base
    has_many :orderItems

  class OrderItem < ActiveRecord::Base
    belongs_to :order

Then in a view you use the association name:

  @order[0].orderItems.each {|line| puts line.item_id + " - " +}

It turns out that you can also use the names "order_items" or
"Order_Items" instead of "orderItems" and that works fine.  I would
expect one or the other to work but not both.

Is ambiguity this by design?

Which should be used according to best practice?

steve (Guest)
on 2005-11-19 20:48
(Received via mailing list)
On Nov 19, 2005, at 10:22 AM, Rick wrote:

> Is ambiguity this by design?


> Which should be used according to best practice?

Rubyists usually use CamlCase for ClassNames.  Personally, I
prefer :order_items for symbol names.  But, the great thing is you
get to use whatever you want!

This topic is locked and can not be replied to.