0
考慮這些作爲我的表結構如何在rails的關係表中的額外列中插入值?
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
end
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
end
我Appointments
表有一個名爲relationship
一個額外的列。每次當我將醫師和患者聯繫起來時,我想添加一種關係[我的例子聽起來很奇怪,我如何在這個列中插入值?
沒有。那也不管用。我收到一個錯誤。 – Rahul
你可以展示你有什麼?當然,上面的代碼會給出錯誤,這只是一個例子。你必須適應你所擁有的東西,但是你沒有展示你的東西。 –
我創建了適當的對象。如果我採用上述樣本,我可以創建患者和醫生對象,但是當我嘗試創建約會時,我得到一個錯誤,說'關係不能爲空',而不管我給':relationship =>'General'同時創建我的約會對象。 – Rahul