0
我必須使用具有多對多關係的表。我創建了正確的表codesecure_project_tst_definition,它的工作原理。我可以通過在TstDefinition對象上調用codesecure_projects < <方法來連接在一起的行。問題是由於某種原因,活動記錄想要使用Codesecure_project_id作爲codesecure_project_tst_definition表的id值。我究竟做錯了什麼?我該如何解決這個問題,以便在我調用codesecure_projects方法時不嘗試設置codesecure_project_tst_definition表的id?Activerecode HABTM主鍵問題
我已經發布了遷移以下
class CreateCodesecureProjects < ActiveRecord::Migration
def self.up
create_table :codesecure_projects do |t|
t.string :name
t.string :lang
t.timestamps
end
end
def self.down
drop_table :codesecure_projects
end
end
class CreateTstDefinitions < ActiveRecord::Migration
def self.up
create_table :tst_definitions do |t|
t.string :test_name
t.timestamps
end
end
def self.down
drop_table :tst_definitions
end
end
class CreateCodesecureProjectsTstDefinitions < ActiveRecord::Migration
def self.up
create_table :codesecure_projects_tst_definitions do |t|
t.references :codesecure_project
t.references :tst_definition
t.timestamps
end
end
def self.down
drop_table :codesecure_projects_tst_definitions
end
end
模型的相關部分:
class TstDefinition < ActiveRecord::Base
has_and_belongs_to_many :codesecure_projects
has_many :tst_datas
class CodesecureProject < ActiveRecord::Base
has_many :input_abstractions
has_and_belongs_to_many :tst_definitions
您能向我們展示關聯行中的類定義嗎? – Gareth 2008-11-03 08:29:49
我無法理解這個問題..張貼表架構..就像加雷思說..發佈AR模型類可能有幫助 – Gishu 2008-11-03 08:32:58