# Load model in component

**URL:** <https://discourse.cakephp.org/t/load-model-in-component/9254>\
**Category:** Need Help\
**Created:** [April 16, 2021, 11:31am UTC](https://discourse.cakephp.org/t/load-model-in-component/9254 "2021-04-16T11:31:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [April 16, 2021, 11:31am UTC](https://discourse.cakephp.org/t/load-model-in-component/9254/1 "2021-04-16T11:31:42Z")

</div>

How to load a model in a component correctly? So I can use this call:

`$settings = $this->Settings->get(1);`

Thank you

---

<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:** [April 16, 2021, 2:36pm UTC](https://discourse.cakephp.org/t/load-model-in-component/9254/2 "2021-04-16T14:36:24Z")

</div>

You can always use `TableRegistry::getTableLocator()->get('Settings')` from anywhere to get the Settings table.

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [April 18, 2021, 6:15pm UTC](https://discourse.cakephp.org/t/load-model-in-component/9254/3 "2021-04-18T18:15:43Z")

</div>

I have annotation:

```
 * @property \App\Model\Table\SettingsTable $Settings
 * @method \App\Model\Entity\Setting[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])

```

And then how to make an annotation to tell me the columns?  
This above works if I call this:

```
$settings = $this->Settings->get(1);
$settings->column

```

If I use your example, it doesn’t tell me the columns.

---

<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:** [April 18, 2021, 6:55pm UTC](https://discourse.cakephp.org/t/load-model-in-component/9254/4 "2021-04-18T18:55:21Z")

</div>

If you `use Cake\Datasource\ModelAwareTrait;`, you’ll be able to use `$this->loadModel('Settings')`. But autocomplete, while nice, isn’t the final arbitrator of what you can do. Up to you to decide whether that developer convenience is worth the extra code required for it.

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [April 19, 2021, 5:23am UTC](https://discourse.cakephp.org/t/load-model-in-component/9254/5 "2021-04-19T05:23:28Z")

</div>

Thank you, it works!
