I’ve started playing with Rails 2.0.2 and I have an issue with fixtures.
It used to work in Rails 1.8.6…
A bit of context first. I have 2 models:
class competition
has_and_belongs_to_many :teams
end
class team
has_and_belongs_to_many :competitions
end
In my competition_test.rb, I have:
def test_teams_association
assert competitions(:competition_one).teams.include? teams(:team_one)
end
First I know that this is testing ActiveRecord more than anything else
but still this test used to pass in Rails 1.8.6 but fails with Rails
2.0.
I printed out competitions(:competition_one).teams.last (if we imagine
that :team_one is indeed the last in the array) and teams(:team_one) and
I get something like:
I bet you have two teams named “Team One”: One that was inserted into
the database before your upgrade to Rails 2 (ID 487), and one after
(ID 607411122). Try dropping your databases and rerunning.
In the test I re-ran, I now had “26” as the id for the
competitions(:competition_one).teams.last which turned out to be one of
the primary key of my competitions_teams table!
I dropped it, recreated it by hand with only competition_id and team_id
columns and it is now all working fine :).
I suppose you always have to create the link tables by hand? Or is there
a Rails way for this too?
Thanks again for your help.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.