Association belongsTo, hasMany and hasOne

Hello, I would like to have information to set up an association for my model “Games”.

Currently I use two belongsTo association with the model “Media”:

        $this->belongsTo('Thumbnails', [
            'className' => 'Media',
            'foreignKey' => 'thumbnail_id'
        $this->belongsTo('Covers', [
            'className' => 'Media',
            'foreignKey' => 'cover_id'

I would like to add a third association with the “Media” model:

    $this->hasMany('Screenshots', [
        'className' => 'Media',
        'foreignKey' => 'game_id',
        'conditions' => ['Screenshots.type' => 'screenshot']

The problem with hasMany is that I have to add a game_id field to the media table.

The only solution I see, would be to change the first two associations into hasOne, which would allow me to use the field “game_id” several times

What do you think ?

Thank you in advance.

I think belongToMany is the best way :grinning: