# Issue with relation tables after adding slug

**URL:** <https://discourse.cakephp.org/t/issue-with-relation-tables-after-adding-slug/7225>\
**Category:** Need Help\
**Created:** [February 4, 2020, 3:24pm UTC](https://discourse.cakephp.org/t/issue-with-relation-tables-after-adding-slug/7225 "2020-02-04T15:24:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://discourse.cakephp.org/u/newbie)\
**Post date:** [February 4, 2020, 3:24pm UTC](https://discourse.cakephp.org/t/issue-with-relation-tables-after-adding-slug/7225/1 "2020-02-04T15:24:19Z")

</div>

@Zuluru

I’ve created the following database tables and created all pk & fk’s  
Partners id PK  
PartnerFacilities partners\_id t FK  
PartnerPegs partners\_id FK  
PartnerWatersSpecies partner\_id FK  
PartnersWaters partners\_id FK

Once populated and selecting view from the index using partner id in the browser it was pulling all the data from each related table to the localhost/apps/mysite/partners/view/1  
using the following code:

```
public function view($id = null)
    {
        $partner = $this->Partners->get($id, [
            'contain' => ['PartnerTypes', 'SubscriptionTypes', 'Users', 'PartnerFacilities', 'PartnerPegs', 'PartnerWatersSpecies', 'PartnersWaters'],
        ]);
        $this->set('partner', $partner);
    }

```

I then added slug using the following code in my PartnersController  
public function view($slug = null)  
{  
$partner = $this-\>Partners-\>findBySlug($slug)-\>firstOrFail([  
‘contain’ =\> [‘PartnerTypes’, ‘SubscriptionTypes’, ‘Users’, ‘PartnerFacilities’, ‘PartnerPegs’, ‘PartnerWatersSpecies’, ‘PartnersWaters’],  
]);  
$this-\>viewBuilder()-\>setLayout(‘partners’);  
$this-\>set(‘partner’, $partner);  
}

I then created the following routes in my routers

```
$builder->connect('/partners/', ['controller' => 'Partners', 'action' => 'index']);
$builder->connect('/partners/add', ['controller' => 'Partners', 'action' => 'add']);
$builder->connect('/partners/*', ['controller' => 'Partners', 'action' => 'view']);

```

I can now see my partner at localhost/apps/mysite/partners/partner-name

It is displaying the populated information from the Partners table, but not rendering the data from the other tables?? at it did with `$partner = $this->Partners->get($id`

how do I write it to get the other tables to render the data from the other tables using the partner\_id

Regards

Mal

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 4, 2020, 4:05pm UTC](https://discourse.cakephp.org/t/issue-with-relation-tables-after-adding-slug/7225/2 "2020-02-04T16:05:39Z")

</div>

The `firstOrFail` function takes no parameters. Try:

```auto
$partner = $this->Partners->findBySlug($slug)
    ->contain([‘PartnerTypes’, ‘SubscriptionTypes’, ‘Users’, ‘PartnerFacilities’, ‘PartnerPegs’, ‘PartnerWatersSpecies’, ‘PartnersWaters’])
    ->firstOrFail();

```

This might also work, but I prefer the former:

```auto
$partner = $this->Partners->findBySlug($slug, ['contain' =>
        [‘PartnerTypes’, ‘SubscriptionTypes’, ‘Users’, ‘PartnerFacilities’, ‘PartnerPegs’, ‘PartnerWatersSpecies’, ‘PartnersWaters’]
    ])
    ->firstOrFail();
```

---

<div class="post-metadata">

**Author:** ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://discourse.cakephp.org/u/newbie)\
**Post date:** [February 4, 2020, 7:47pm UTC](https://discourse.cakephp.org/t/issue-with-relation-tables-after-adding-slug/7225/3 "2020-02-04T19:47:00Z")

</div>

@Zuluru both ways worked a charm, thanks 😃
