# Alternative Key in Model

**URL:** https://discourse.cakephp.org/t/alternative-key-in-model/10216
**Category:** Need Help
**Created:** [March 9, 2022, 11:55am UTC](https://discourse.cakephp.org/t/alternative-key-in-model/10216 "2022-03-09T11:55:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Klaus](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/klaus/32/269_2.png) [@Klaus](https://discourse.cakephp.org/u/Klaus)
#### Post date: [March 9, 2022, 11:55am UTC](https://discourse.cakephp.org/t/alternative-key-in-model/10216/1 "2022-03-09T11:55:38Z")

</div>

Hallo,  
I am just fighting with a problem on relations in Models.  
I have moved from the conventions changing the primary key.  
$this-\>setTable(‘accounts’);  
$this-\>setDisplayField(‘name’);  
$this-\>setPrimaryKey(‘account\_no’);  
and  
$this-\>hasMany(‘Costcenters’, [‘foreignKey’ =\> ‘account\_no’,]);

That works fine. The purpose is I have to avoid lots of new entries each new year. OK so far so good, but I need an additional relationship like:

```
   $this->hasMany('Journals', ['foreignKey' => 'actAccount',]);

```

which is containing the id of the related account.  
Can I have both? I read the cookbook/Table Objects several times but have not found the way.  
Thanks in advance

---

<div class="post-metadata">

### Author: ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)
#### Post date: [March 11, 2022, 5:44pm UTC](https://discourse.cakephp.org/t/alternative-key-in-model/10216/2 "2022-03-11T17:44:44Z")

</div>

you can add as many associations to your table as you like

```auto
        $this->belongsTo('Projects', [
            'foreignKey' => 'project_id',
            'joinType' => 'INNER',
        ]);
        $this->belongsTo('EasybillDocuments', [
            'foreignKey' => 'easybill_document_id',
            'joinType' => 'INNER',
        ]);
        $this->belongsTo('ProjectDocumentTypes', [
            'foreignKey' => 'project_document_type_id',
            'joinType' => 'INNER',
        ]);

```

just put them underneath each other
