我正在ROR中構建多客戶系統。 (我正在查看http://guides.rubyonrails.org/association_basics.html#polymorphic-associations)數據庫結構 - 多用戶系統中的關聯
結構是客戶端有合同,所以當他用他的用戶名,密碼和合同登錄時,他將有權訪問系統。
我們將合同標識作爲「主密鑰」,必須位於系統的每個表中。
class CreateContracts < ActiveRecord::Migration
def change
create_table :contracts do |t|
t.integer :contract_id
end
end
end
(會計科目表)
class CreateCoas < ActiveRecord::Migration
def change
create_table :coas do |t|
t.integer :account_id
t.string :account_name
end
end
end
class CreateCustGroups < ActiveRecord::Migration
def change
create_table :custgroups do |t|
t.integer :account_id1
t.integer :account_id2
t.integer :account_id3
end
end
end
Q1:如何定義與belongs_to的合同?系統中的每個表格都必須與合同表有關係。我是否必須與所有表格有關係? (我認爲是)
class Contracts < ActiveRecord::Base
has_and_belongs_to_many :Coas
has_many:xxx
belongs:to
end
問題2:如何定義custgroup上的關聯?在這裏我們有一個記錄,其中有3個或更多鏈接到同一個表(COA)的字段。
如果你更詳細地解釋了不同模型之間的關係,這將會有所幫助。現在,很難理解你想要達到的目標。 – Jesper
喜加斯帕訂做下面 – mickdane