From: Raul Parolari Date: 2007-11-28T14:03:25+09:00 Subject: Re: failry simple(?) active record question. Kyle Schmitt wrote: > Take a really simple example > > ActiveRecord::Schema.define() do > create_table :containers do |table| > table.column :name, :string > end > create_table :things do |table| > table.column :description, :string > end > end > .. > #but howcome > pocket.things.find(:all) > #throws some huge error instead of finding the things in the pocket? Kyle, when you have a relationship 'belongs_to', you need to define a field in the database table to references the parent (the name is _id), as ActiveRecord does not create this field automatically. So, we just need a 'container_id' in the 'things' table: ActiveRecord::Schema.define() do create_table :containers do |table| table.column :name, :string end create_table :things do |table| table.column :description, :string table.column :container_id, :integer # <-- here end end Your example runs now fine. You could also add an index (with 'add_index') for performance. Regards Raul -- Posted via http://www.ruby-forum.com/.