Here is my simple example...
require 'rubygems' require 'active_record'
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "has_many_through.db" ActiveRecord::Schema.define do create_table "containers", :force => true do |t| t.column :name, :string end
create_table "shapes", :force => true do |t| t.column :name, :string t.column :container_id, :integer end
create_table "colors", :force => true do |t| t.column :name, :string t.column :shape_id, :integer end end
class Container < ActiveRecord::Base has_many :shapes has_many :colors, :through => :shapes end
class Shape < ActiveRecord::Base has_one :color end
class Color < ActiveRecord::Base end
container = Container.create! :name => "Container 1" shape1 = container.shapes.create! :name => "Shape 1" shape2 = container.shapes.create! :name => "Shape 2" shape3 = container.shapes.create! :name => "Shape 3" shape1.create_color :name => "Color 1"
puts container.colors.inspect
reflection.rb:191 check and makes sure the source is either a belongs_to or has_many... Why is has_one excluded?