0
我有一個叫做User的模型,與興趣有很多關係。爲什麼datamapper試圖重新保存我的關係?
比方說,連接表看起來是這樣的:
User ID | Interest ID
---------------------
5 | 1
當我編輯該用戶的名稱(例如),並調用user.save
,它失敗。
它失敗的原因是因爲datamapper(AFAIK)試圖重新保存與興趣的關係。我得到的錯誤是:
duplicate key value violates unique constraint "user_interests_pkey"
DETAIL: Key (user_id, interest_id)=(5, 1) already exists.
有沒有人遇到過這個問題?任何人都知道解決方案?預先感謝您的幫助。
UPDATE
用戶模型看起來LIK:
class User
include DataMapper::Resource
has n, :interests, :through => Resource, :constraint => :skip
end
鑑於興趣模型的樣子:
class Interest
include DataMapper::Resource
has n, :users, :through => Resource, :constraint => :skip
end
我已經添加了模型關係規範 - 它是原始問題中提到的多對多關係。謝謝! – Ger