# Loading models -- A question on how to do it properly

**URL:** <https://discourse.cakephp.org/t/loading-models-a-question-on-how-to-do-it-properly/3752>\
**Category:** Need Help\
**Created:** [January 13, 2018, 7:41pm UTC](https://discourse.cakephp.org/t/loading-models-a-question-on-how-to-do-it-properly/3752 "2018-01-13T19:41:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zapatos](https://avatars.discourse-cdn.com/v4/letter/z/c5a1d2/32.png) [@zapatos](https://discourse.cakephp.org/u/zapatos)\
**Post date:** [January 13, 2018, 7:41pm UTC](https://discourse.cakephp.org/t/loading-models-a-question-on-how-to-do-it-properly/3752/1 "2018-01-13T19:41:19Z")

</div>

Hello,  
What is the difference if I load a model versus table registry in another controller? If I am loading 1 entity, why is one better than the other?

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

```

vs Entity  
$articles = TableRegistry::get(‘Articles’);

---

<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:** [January 15, 2018, 11:54am UTC](https://discourse.cakephp.org/t/loading-models-a-question-on-how-to-do-it-properly/3752/2 "2018-01-15T11:54:29Z")

</div>

[https://book.cakephp.org/3.0/en/controllers.html#loading-additional-models](https://book.cakephp.org/3.0/en/controllers.html#loading-additional-models)

$this-\>loadModel can use defined connector to load “tables” other then RDB  
TableRegistry is a connector used to load RDB tables, and is used as default connector for $this-\>loadModel

In case of RDB tables there is no any big difference, but I would stick to this-\>loadModel if you want to avoid refactoring in the future.

---

<div class="post-metadata">

**Author:** ![zapatos](https://avatars.discourse-cdn.com/v4/letter/z/c5a1d2/32.png) [@zapatos](https://discourse.cakephp.org/u/zapatos)\
**Post date:** [January 15, 2018, 5:45pm UTC](https://discourse.cakephp.org/t/loading-models-a-question-on-how-to-do-it-properly/3752/3 "2018-01-15T17:45:53Z")

</div>

So the Table registry is a strict implementation of loading an RDB table, and load model is more conventional api?

---

<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:** [January 15, 2018, 7:49pm UTC](https://discourse.cakephp.org/t/loading-models-a-question-on-how-to-do-it-properly/3752/4 "2018-01-15T19:49:28Z")

</div>

Yes, TableRegistry is just a factory designated to load/create RDB tables , loadModel comes from ModelAwareTrait wich uses such factories to load any model. I would use a trait’s loadModel() over static TableRegistry as it seams to be more correct way, and TableRegistry should not be even mentioned in a book since we have that trait.

[https://api.cakephp.org/3.5/source-class-Cake.Datasource.ModelAwareTrait.html](https://api.cakephp.org/3.5/source-class-Cake.Datasource.ModelAwareTrait.html)
