Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Record set_table_name error for .sqlite file

I'm trying to interact with a .sqlite file by connecting to it with Active Record. I'm doing this:

require 'active_record'

# Connect to DB
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => 'database.sqlite')

# Log the tables to make sure Active Record is connected to the DB correclty
puts ActiveRecord::Base.connection.tables

# Map from existing table records to a Active Record model
class Patient < ActiveRecord::Base
  set_table_name "ZPATIENT"
end

The connection to the database works as printing out the database tables gives:

ZPATIENT
ZZCONFIG
Z_PRIMARYKEY
Z_METADATA

But the attempt to map ZPATIENT table to Patient Active Record models fails with:

~/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `set_table_name' for Patient(Table doesn't exist):Class (NoMethodError)
    from script.rb:8:in `<class:Patient>'
    from script.rb:7:in `<main>'

Not sure what I am doing wrong? Do I need to do some sort of migration for Active Record to understand how to map the table to models?

like image 954
lukestringer90 Avatar asked Jul 05 '13 23:07

lukestringer90


1 Answers

set_table_name was removed. Try with:

class Patient < ActiveRecord::Base
  self.table_name = 'ZPATIENT'
end
like image 111
alf Avatar answered Oct 25 '22 09:10

alf