# Associated model in Cells

**URL:** <https://discourse.cakephp.org/t/associated-model-in-cells/3922>\
**Category:** Uncategorized\
**Created:** [February 14, 2018, 9:44am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922 "2018-02-14T09:44:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 14, 2018, 9:44am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/1 "2018-02-14T09:44:59Z")

</div>

Do associations work in cells ?  
-\>contain([‘myAssociatedModel’])  
does not work in my cells and return an error message (is not associated).

Associations works everywhere else in my app.  
Commenting the line make cell work but I miss the associated data.

---

<div class="post-metadata">

**Author:** ![Marcel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/marcel/32/329_2.png) [@Marcel](https://discourse.cakephp.org/u/Marcel)\
**Post date:** [February 16, 2018, 2:48pm UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/2 "2018-02-16T14:48:14Z")

</div>

Yes they work, could you paste that cumbersome code?

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 16, 2018, 6:14pm UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/3 "2018-02-16T18:14:24Z")

</div>

```
namespace Medias\View\Cell;

```

use Cake\View\Cell;

/\*\*

- Affiches cell  
\*/  
class AffichesCell extends Cell  
{

This cell is within Medias plugin.

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [February 19, 2018, 11:31pm UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/4 "2018-02-19T23:31:05Z")

</div>

you have nothing in `->select()` from `Dossiers`, so you need to pass anything in `->select` from it or `->enableAutofields(true)` or pass whole schema `->select($this->Fichires->Dossiers)`

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 20, 2018, 12:07am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/5 "2018-02-20T00:07:25Z")

</div>

Thank you for trying to help.  
Graziel :  
I use contain([‘Dossiers’]) in some table methods or in my controller and it works perfectly.  
But I tried your way and get the same result :  
Warning (512): Could not render cell - Fichiers is not associated with Dossiers [/home/wmcmiinz/www/matapeste\_2018/vendor/cakephp/cakephp/src/ORM/EagerLoader.php, line 428] [CORE/src/View/Cell.php, line 271]

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [February 20, 2018, 12:53am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/6 "2018-02-20T00:53:46Z")

</div>

can you post your `FichiersTable` ?

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 20, 2018, 1:01am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/7 "2018-02-20T01:01:05Z")

</div>

I GOT IT !

Even though the cell is within a plugin, you have to specify the plugin name.  
So you must load your model this way : $this-\>loadModel(‘Medias.Fichiers’);

Hope it helps someone.

Thank you everybody for your time and knowledge.

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 20, 2018, 1:20am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/8 "2018-02-20T01:20:10Z")

</div>

Well, I was wondering if this could be considered almost a bug ?  
When you are inside a plugin namespace, you should not have to add the plugin name.  
I started with “namespace Medias\View\Cell;” (Medias is the plugin name)  
Or maybe I forgot or missed something.

---

<div class="post-metadata">

**Author:** ![Marcel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/marcel/32/329_2.png) [@Marcel](https://discourse.cakephp.org/u/Marcel)\
**Post date:** [February 25, 2018, 7:52am UTC](https://discourse.cakephp.org/t/associated-model-in-cells/3922/9 "2018-02-25T07:52:04Z")

</div>

Not quite.

In most cases (plugin extends the core functionality of app), it’s handier when its done this way coz by default plugins are loading app models.
