我试图通过卡纳克民阵(mouth!)的关系,把我的头接在两头上。
I m working on a picture matching website.
- Pictures are associated to other pictures via a match (the join model).
- Each match has two pictures and stores the current rating and the total number of votes.
- When viewing a picture, all of its related images from either direction should be available (via its matches).
我先通过与加入模式的关系来界定 has。
表格中的图象是:
id | picture_id | partner_id | rating | total_votes
我加入示范协会就是这样:
class PictureMatch extends AppModel {
...
public $belongsTo = array(
Picture => array(
className => Picture ,
foreignKey => picture_id ,
conditions => ,
fields => ,
order =>
),
Partner => array(
className => Picture ,
foreignKey => partner_id ,
conditions => ,
fields => ,
order =>
)
);
}
Each picture needs to be able to access its related pictures from either direction, but this is where my grasp is slipping. It looks like I need to save both sides of the relationship but this destroys the extra data stored in the join model - with two db entries, voting could vary depending on the direction.
Can anyone shed any light on the best way to do this in CakePHP? I m rather confused.
Is it possible to create the inverse relationships on the fly?