Foreign key problem - 'key not found' error


#1

Hello,

I have the following structure:

model foo
has_many :bars:,
:dependent => true
end

model bar
belongs_to :foo
end


I’m doing the following to insert the Foo record and it’s dependent Bar
record:

f = Foo.create(…)

This successfully creates and stores f away in the table.

Now,

b = Bar.new(params[…])
f.bars << b <-- This should set the foreign key in b automatically.

But I get a ‘key not found’ problem. I get the same problem if I do:

f.bars.create(params[…])

Any help on this would be appreciated. I’ve been on this bug for 2 days
now. Thanks.