我有以下表之間:'assets', 'pictures', 'assets_pictures', 'othermodels', 'othermodels_pictures'
,等...CakePHP的兩個關係模型
從上面的你可能已經想通表'pictures'
作爲圖像庫,並與多個車型,其中包括資產」。
我想模擬'Asset'
(表'assets'
),有:
hasMany
關係與'Picture'
(使用表'assets_pictures'
)hasOne
關係與'Cover'
(表'pictures'
)的基礎上,'assets'
一個'cover_id'
場與'Picture.id'
到目前爲止,當我在Asset
和Picture
和'Asset' belongsTo 'Cover'
之間設置HABTM
關係時似乎工作。不知何故,這聽起來不對,此外,更改資產的封面圖片會清除'assets_pictures'
中關於該資產的所有HABTM
關係,所以我知道這裏有些問題。我迷路了...
probabily你必須設置'」獨特的'=>'keepExisting'在設置您的HABTM關係時,請查看[手冊](http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html# hasandbelongstomany-habtm) – arilia