Forum: Ruby on Rails foreign key problem - 'key not found' error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sam D. (Guest)
on 2006-05-24 01:01
(Received via mailing list)

I have the following structure:

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

model bar
  belongs_to :foo

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

f = Foo.create(...)

This successfully creates and stores f away in the table.


b =[...])
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:


Any help on this would be appreciated.  I've been on this bug for 2 days
now.  Thanks.
This topic is locked and can not be replied to.