K
Kyle Schmitt
I'm plodding my way through active record right now, and running into
some things that seem odd.
Take a really simple example
#!/usr/bin/ruby
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connectionadapter => "sqlite3",
:database => "foo.db")
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
class Container<ActiveRecord::Base
has_many :things
end
class Thing<ActiveRecord::Base
belongs_to :container
end
Container.createname=>"Bucket")
bucket=Container.find_by_name("Bucket")
pocket=Container.createname=>"Pocket")
bucket.save
pocket.save
Container.findall)
#this will find both containers
Thing.findall)
#empty, as expected
bucket.things.createdescription=>"fish")
pocket.things.createdescription=>"lint")
Thing.findall)
#looks good...
#but howcome
pocket.things.findall)
#throws some huge error instead of finding the things in the pocket?
Sorry for the overly newbie type question I just really thought
ActiveRecord was supposed to take care of all this stuff.
Thanks,
Kyle
some things that seem odd.
Take a really simple example
#!/usr/bin/ruby
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connectionadapter => "sqlite3",
:database => "foo.db")
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
class Container<ActiveRecord::Base
has_many :things
end
class Thing<ActiveRecord::Base
belongs_to :container
end
Container.createname=>"Bucket")
bucket=Container.find_by_name("Bucket")
pocket=Container.createname=>"Pocket")
bucket.save
pocket.save
Container.findall)
#this will find both containers
Thing.findall)
#empty, as expected
bucket.things.createdescription=>"fish")
pocket.things.createdescription=>"lint")
Thing.findall)
#looks good...
#but howcome
pocket.things.findall)
#throws some huge error instead of finding the things in the pocket?
Sorry for the overly newbie type question I just really thought
ActiveRecord was supposed to take care of all this stuff.
Thanks,
Kyle