Issue with relation tables after adding slug


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->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



The firstOrFail function takes no parameters. Try:

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

This might also work, but I prefer the former:

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

@Zuluru both ways worked a charm, thanks :smiley: