0
我练习了我的RoR技能并尝试将应用程序开发为已创建的数据库。它有4个表格:testplans,testplan_tcversions,* test_project *和节点。使用has_many时未初始化的常量NameError
我的代码2款此表:
class TestPlan < ActiveRecord::Base
self.table_name= 'testplans'
belongs_to :test_project
has_many :test_suites, foreign_key: :testplan_id, inverse_of: :test_plan
has_one :node, foreign_key: :id, inverse_of: :test_plan
end
和
class TestSuite < ActiveRecord::Base
self.table_name='testplan_tcversions'
belongs_to :test_plan
has_one :node, foreign_key: id, inverse_of: :test_collection
end
,但我得到异常未初始化的不断测试计划:: TestSuite的时候尝试:@suits=TestPlan.find(4906).test_suites
我找到了很多答案,模型必须单数,表格必须是复数,但我的模型名称是单数,表格名称指向self.table_name。
我做错了什么?
UPD
这是我的DB:架构:甩
create_table "testplans", force: true do |t|
t.integer "testproject_id"
t.text "notes"
t.integer "active"
t.integer "is_open"
t.integer "is_public"
t.text "api_key"
end
create_table "testplan_tcversions", force: true do |t|
t.integer "testplan_id"
t.integer "tcversion_id"
t.integer "node_order"
t.integer "urgency"
t.integer "platform_id"
t.integer "author_id"
t.datetime "creation_ts"
end
我使用已经创建的数据库,并没有写入迁移,因为数据库拥有所有包含字段和数据的表。 TestSuite有'_test_plan_id_列,但是_testplan_id_并且我指向'foreign_key::testplan_id'。表名不对应模型名称,我使用'self.table_name =' – 2014-08-30 05:13:32