- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试通过使用 Active Record 连接到 .sqlite 文件来与它交互。我这样做:
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
与数据库的连接就像打印出数据库表一样:
ZPATIENT
ZZCONFIG
Z_PRIMARYKEY
Z_METADATA
但是将 ZPATIENT
表映射到 Patient Active Record 模型的尝试失败了:
~/.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>'
不确定我做错了什么?我是否需要对 Active Record 进行某种迁移以了解如何将表映射到模型?
最佳答案
set_table_name
已被删除。尝试:
class Patient < ActiveRecord::Base
self.table_name = 'ZPATIENT'
end
关于ruby - .sqlite 文件的 Active Record set_table_name 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17498147/
我在 Mac OSX 10.6.4 上运行 ruby,使用 Ruby 1.8 和 activerecord 2.3.8。我在 NetBeans 6.9 中运行以下代码,但我使用的是 10.6 中的
我正在使用 Rails3 Edge 和 mongoid 2beta6 以及 ruby 1.9.2-head。 如何手动更改表名称,就像 ActiveRecord 的 set_table_name
我正在尝试通过使用 Active Record 连接到 .sqlite 文件来与它交互。我这样做: require 'active_record' # Connect to DB ActiveReco
由于遗留原因,我模型的表存储在同一 MySQL 服务器上的两个不同数据库中。起初我只是使用 establish_connection 在使用它的模型上指定第二个数据库。但是,当我在不同数据库中的两个模
我正在使用 Rails 2.3.14 UPDATE 3 我在更新 2 中发现的技巧仅适用于关联的首次访问...因此,我将 set_table_name 行粘贴到我的应用程序 Controller 中。
我是一名优秀的程序员,十分优秀!