Difficulty figuring out this model association..

Essentially, I want to achieve something like this:
http://pastie.org/private/0yuhxeqyheqov3pzkhnga

Item model that can contain many Items that are required to create that
Item.

I'm new to rails, and having a hard time figuring out how to make this
happen. Any guidance, is greatly appreciated.

Joshua Kappers <lists@...> writes:

Essentially, I want to achieve something like this:
http://pastie.org/private/0yuhxeqyheqov3pzkhnga

Item model that can contain many Items that are required to create that
Item.

I'm new to rails, and having a hard time figuring out how to make this
happen. Any guidance, is greatly appreciated.

# Item

item_id, name
1, Wood
2, Copper Ore
3, Copper Sword

# ItemComponents

compound_id, item_id, amount
3, 1, 5
3, 2, 8

# Models

Item << ActiveRecord::Base
  has_many :item_components
end

ItemComponent < ActiveRecord:Base
  belongs_to :item
  belongs_to :compound
end

Compound << ActiveRecord::Base
  has_many :item_components
end

Andf change the view code to work:

@item.find(3).item_components.each do |component|
  <%= item.name %> <%= component.amount %>
end