I have...
app/models/report.rb:
has_and_belongs_to :standards
app/models/standard.rb:
has_and_belongs_to :reports
db/schema.rb:
create_table "reports_standards", :id => false, :force => true do |t|
t.integer "report_id"
t.integer "standard_id"
end
When I log into rails console, all seems OK initially...
> @report = Report.create :name => "foo"
=> #<Report id: 2, name: "foo", created_at: "2013-02-21 03:10:06", updated_at: "2013-02-21 03:10:06">
> @standard = @report.standards.build :name => "bar"
=> #<Standard id: nil, name: "bar", created_at: nil, updated_at: nil>
> @report.standards
=> [#<Standard id: nil, name: "bar", created_at: nil, updated_at: nil>]
...but then it turns strange...
> @standard.reports
=> []
Isn't it meant to be:
> @standard.reports
=> [#<Report id: 2, name: "foo", created_at: "2013-02-21 03:10:06", updated_at: "2013-02-21 03:10:06">]
Why isn't it? How do I fix it?