I'm trying to figure out bidirectional self-referencing hasMany through relationships in CakePHP (what a sip!).
I am working on a site that matches the picture.
- Images are linked to other images through a “match” (association model).
- Each match has two photos and saves the current rating and the total number of votes.
- When viewing an image, all images associated with it from any direction should be accessible (through its coincidence).
I started by defining a hasMany relationship with the connection model.
The join_matches join table has this structure:
id | picture_id | partner_id | rating | total_votes
My union link association looks like this:
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' => ''
)
);
}
, , .
, , , - , .
- CakePHP? .
" "?