我有以下表之间:'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