Forum: Ruby on Rails act_as_tree, belongs_to and has_many foreign keys incorrect

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C8840bff779d9acaa15d1628f7869d12?d=identicon&s=25 stephen O'D (Guest)
on 2007-07-05 17:22
(Received via mailing list)
Two models:

class Project << ActiveRecord::Base
  has_many :files
end

class File << ActiveRecord::Base
  has_one :project
  acts_as_tree
end

Inside of the project model, when creating a new product, I want to
store the hierarchy of files within it.

If I do,

my_top_level_file = my_project_object.files.create(:file_name =>
'foo');
my_top_level_file.children.create(:file_name => 'bar')

When the data gets saved, the first row in the Files table gets the
new product_id value that is also inserted into the Projects table,
but the child row does not, giving me results like:

Projects:
  id: 1
  name: A_Name

Files:
  id: 1
  project_id: 1
  parent_id: null
  filename: foo

  id: 2
  product_id: 0 <---------------------- Should this not be 1?
  parent_id: 1
  filename: bar

Firstly, am I doing things right?  If so, is this a bug, or is this
how things were intended to work?  Surely all rows in the files table
should have the correct foreign key attached to them?

Thanks,

Stephen.
This topic is locked and can not be replied to.