# Multiple modal used another controller get value from model

**URL:** <https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962>\
**Category:** Need Help\
**Created:** [June 19, 2020, 1:39pm UTC](https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962 "2020-06-19T13:39:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naveenmdr](https://avatars.discourse-cdn.com/v4/letter/n/b19c9b/32.png) [@Naveenmdr](https://discourse.cakephp.org/u/Naveenmdr)\
**Post date:** [June 19, 2020, 1:39pm UTC](https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962/1 "2020-06-19T13:39:23Z")

</div>

I have a two model  
Job  
Enquiry

Job controller get the query  
$jobcard = $this-\>Jobcard-\>get($jcid, [

```
        'contain' => []

    ]);

```

$this-\>Jobcard-\>hasMany(‘Enquiry’, [

```
                'foreignKey' => 'id']);

```

$enquiry2 = $this-\>Jobcard-\>Enquiry-\>get($enqid, [

```
        'contain' => []

    ]);

```

it’s working in Job controller. i want the same query run another controller that is passible?

---

<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:** [June 19, 2020, 2:24pm UTC](https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962/2 "2020-06-19T14:24:15Z")

</div>

Either use `loadModel` to add the model in question to what is directly available through `$this`, or use the `TableRegistrty` to get that model. Then run the query just as you have it.

---

<div class="post-metadata">

**Author:** ![Naveenmdr](https://avatars.discourse-cdn.com/v4/letter/n/b19c9b/32.png) [@Naveenmdr](https://discourse.cakephp.org/u/Naveenmdr)\
**Post date:** [June 19, 2020, 2:49pm UTC](https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962/3 "2020-06-19T14:49:43Z")

</div>

> [@Zuluru](#):
>
> `loadModel`

Hi @Zuluru  
i try TableRegistry::get(‘Jobcard’)-\>get($id) this one but i can get one model value. but i want to join another modal also. I bit confusion . Send the sample query get the two modal values

i try load modal also  
$this-\>loadModel(‘Jobcard’);

```
            $this->loadModel('Enquiry');

          

           // $jobcard = $this->Jobcard->get($id, ['Enquiry'

            $enquiry2 = $this->Jobcard->Enquiry->get(350, [

                'contain' => []

            ]);

```

i got the error like this  
Undefined property `Enquiry`. You have not defined the `Enquiry` association on `App\Model\Table\JobcardTable`.

---

<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:** [June 19, 2020, 3:47pm UTC](https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962/4 "2020-06-19T15:47:19Z")

</div>

> [@Naveenmdr](#):
>
> $this-\>Jobcard-\>hasMany(‘Enquiry’

This call is in your Job controller, not in the JobcardTable initialization function? If so, that’s why the association isn’t available in the other place. Just like it says " You have not defined the `Enquiry` association".

---

<div class="post-metadata">

**Author:** ![Naveenmdr](https://avatars.discourse-cdn.com/v4/letter/n/b19c9b/32.png) [@Naveenmdr](https://discourse.cakephp.org/u/Naveenmdr)\
**Post date:** [June 19, 2020, 4:09pm UTC](https://discourse.cakephp.org/t/multiple-modal-used-another-controller-get-value-from-model/7962/5 "2020-06-19T16:09:37Z")

</div>

> [@Naveenmdr](#):
>
> hasMany

Thank you @Zuluru. 😀 😀 it works
