Hi -- On Tue, 21 Nov 2006, Chris Gallagher wrote: > Hi, > > Im currently writing a ruby script that will connect to a database using > active record and then insert data that has been scraped from certain > websites. > > A problem that I have run into is that when i try to use the .save > command i receive the following error: > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb: > ': Mysql::Error: Unknown column 'id' in 'where clause': UPDATE results > SET `module_name` = '--- !ruby/object: > \nentity_filter: \nnormalized: \nparent: \nraw: true\nstring: > henry-mobile-server\nunnormalized: \n', `build > tp://10.37.150.55:8080', `build_status_since` = '12:42', `build_number` > = 'build.16', `last_failure` = NULL, > ss` = '20/11/06' WHERE id = NULL (ActiveRecord::StatementInvalid) > > This is clearly due to the fact that I dont have any id fields in my > database as i thought that active record would do something similar to > rails and that i wouldnt have to define them? Obviously this isnt quite > the case? > > the code that im using for this segment of the script is as follows: > > Result.find(:all,:conditions => ["build_url = ?", > records.build_url]).each do |b| > puts b.id > b.build_status_since = build_status_since > b.save > end > > Is there a work around for this problem or am I missing the problem > completely here? The id field is automatically created when you use ActiveRecord Migrations. Otherwise, you have to create it yourself. David -- David A. Black | dblack / rubypal.com Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org