Problem with plurals, migrations?

Hi,

Ruby 1.8.4
Rails 1.1.4
Windows XP Pro

I’m hitting an issue with migrations that I suspect relates to
pluralization. Here’s the migration:

class Hardware < ActiveRecord::Migration
def self.up
create_table :hardware do |h|
h.column :vendor, :string, :limit => 32
h.column :model, :string, :limit => 32
end

  Hardware.create(:vendor => 'Foo', :model => 'Bar')

end

def self.down
drop_table :hardware
end
end

Here’s the model:

class Hardware < ActiveRecord::Base
set_table_name “hardware”
has_many :schedules
end

When I run the migration the table creation occurs, but then I get this
error:

– create({:vendor=>“Foo”, :model=>“Bar”})
rake aborted!
undefined method `create’ for
#ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x39293cc

My guess is that it was expecting a “hardwares” table instead of
“hardware”, and is getting confused. But, I didn’t see a method in the
docs to set the table name ala ActiveRecord.

Or am I missing something obvious here? I checked the docs and Google,
but didn’t find anything.

Below is the full trace.

Thanks,

Dan

rake aborted!
undefined method create' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x39293cc> c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig ration.rb:272:insend’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig
ration.rb:272:in method_mis sing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig ration.rb:256:insay_with_t
ime’
c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig ration.rb:256:insay_with_t
ime’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig
ration.rb:270:in method_mis sing' ./db/migrate//004_hardware.rb:13:inreal_up’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig
ration.rb:210:in migrate' c:/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig
ration.rb:210:in migrate' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig ration.rb:332:inmigrate’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig
ration.rb:327:in migrate' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig ration.rb:294:inup’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/mig
ration.rb:285:in migrate' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/tasks/databases.rake:4 c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:ininvoke’
c:/ruby/lib/ruby/1.8/thread.rb:135:in synchronize' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:ininvoke’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
c:/ruby/bin/rake.bat:25

This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.

Hi –

On Tue, 8 Aug 2006, Berger, Daniel wrote:

def self.up
end
error:

y – create({:vendor=>“Foo”, :model=>“Bar”})

rake aborted!
undefined method `create’ for
#ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x39293cc

My guess is that it was expecting a “hardwares” table instead of
“hardware”, and is getting confused. But, I didn’t see a method in the
docs to set the table name ala ActiveRecord.

Could the problem be that you’ve got two classes named Hardware?
Maybe name the migration class CreateHardware and see what happens.

David


http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack’s][ Web]log
Ruby for Rails => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.