Taking time off from programming is always painful :-).
I have the following Models:
====
class Tag < ActiveRecord::Base
has_and_belongs_to_many :problems
end
class Problem < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :tags
end
And the following migrations:
====
create_table “problems” do |t|
t.column “user_id”, :integer
t.column “title”, :string
t.column “description”, :text
t.column “created_at”, :datetime
t.column “updated_at”, :datetime
end
create_table “tags” do |t|
t.column “name”, :string
t.column “created_at”, :datetime
t.column “updated_at”, :datetime
end
create_table “problems_tags” do |t|
t.column “problem_id”, :integer
t.column “tag_id”, :integer
end
Now, from the console I do the following:
====
problem = Problem.find(1)
problem.tags.create :name => “test this tag”
The problem is that a row is added to the Tags table but nothing is
added to the problems_tags table. What am I doing wrong?
I hate being rusty. I can’t seem to find the answer anywhere. I am
sure it is really simple.
Thanks for all your help.
John K.
http://www.kopanas.com
============================================================
http://www.soen.info - Index of online software engineering knowledge
http://www.cusec.net - Canadian University Software Engineering
Conference
http://www.soenlive.com - Presentations from CUSEC