Mariko C. wrote:
Say I have a model called Order. Can I specify that an order “:has_many
That is, an order has many other orders associated with it.
I’m trying to do this, but I’m getting an error saying “undefined method
order.” Is there a join table that I need to create?
Thanks in advance.
This is called a self-referential many-to-many relationship. Example,
using your ‘orders’, where some orders could be considered suborders of
Class Order < ActiveRecord::Base
:class_name => “Order”,
:join_table => “suborders_orders”,
:association_foreign_key => “suborder_id”,
:foreign_key => “order_id”
then you can
order1main = Order.new(…)
order1suborder = Order.new(…)
order1main.suborders << order1suborder