Forum: Ruby on Rails Model associations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
01ec89b682c7ae076d25c39a70def227?d=identicon&s=25 Rick (Guest)
on 2005-11-19 19:22
How does Active Record determine what tables to use when you define an
association?  For example


  class Order < ActiveRecord::Base
    has_many :orderItems
  end

  class OrderItem < ActiveRecord::Base
    belongs_to :order
  end

Then in a view you use the association name:

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

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?

Rick
280b41a88665fd8c699e83a9a25ef949?d=identicon&s=25 steve (Guest)
on 2005-11-19 19:48
(Received via mailing list)
On Nov 19, 2005, at 10:22 AM, Rick wrote:

> Is ambiguity this by design?

Yes.

> 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!

--Steve
This topic is locked and can not be replied to.