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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---