Syntax for calling the has_many class methods

Jeff
Wed, 11 Oct 2006 14:27:58 -0000

I have a simple Active Record model:

class Order < ActiveRecord::Base
  has_many  :line_items
  def add_line_items_from_cart(cart)
    cart.items.each do |item|
      li = LineItem.from_cart_item(item)
      line_items << li
    end
  end
end

This syntax works fine:
 line_items << li

This also works:
 self.line_items << li

But this syntax fails with an error (undefined method `line_items'' for
Order:Class):
 Order.line_items << li

Why the error?

Thanks,
Jeff