# Sort a result made with get

**URL:** <https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741>\
**Category:** Uncategorized\
**Created:** [April 27, 2020, 5:26pm UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741 "2020-04-27T17:26:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Julian](https://discourse.cakephp.org/u/Julian)\
**Post date:** [April 27, 2020, 5:26pm UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741/1 "2020-04-27T17:26:16Z")

</div>

Hello, im new using cakephp so i dont know so much about the framework, as tittle says im trying to sort a result of a get method, also my get query is made with multiple associations and i want to sort a sub-associated content.

---

<div class="post-metadata">

**Author:** ![Julian](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Julian](https://discourse.cakephp.org/u/Julian)\
**Post date:** [April 27, 2020, 6:19pm UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741/2 "2020-04-27T18:19:41Z")

</div>

I have already done it, i just added “‘sort’ =\> ‘“field” ASC’” on my associated model table.

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [April 27, 2020, 6:51pm UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741/3 "2020-04-27T18:51:20Z")

</div>

What does your code look like? Does it match [this expample](https://book.cakephp.org/4/en/orm/retrieving-data-and-resultsets.html#sorting-contained-associations)?

---

<div class="post-metadata">

**Author:** ![Julian](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Julian](https://discourse.cakephp.org/u/Julian)\
**Post date:** [April 28, 2020, 12:42am UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741/4 "2020-04-28T00:42:19Z")

</div>

No, that form doesnt work with ‘get’  
$this-\>hasMany('Table,[

```
        'foreignKey' => 'idTable',

        'sort' => 'Table.idTable ASC'

    ]);

```

this is done in my associated table

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [April 28, 2020, 12:47am UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741/5 "2020-04-28T00:47:40Z")

</div>

what kind of result are you getting? unsorted data? no data? an error?

---

<div class="post-metadata">

**Author:** ![Julian](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Julian](https://discourse.cakephp.org/u/Julian)\
**Post date:** [April 28, 2020, 12:59am UTC](https://discourse.cakephp.org/t/sort-a-result-made-with-get/7741/6 "2020-04-28T00:59:55Z")

</div>

im calling data from some associations of associations ex:  
$query = $this-\>myModel-\>get($id, [

```
        'contain' => ['table' => ['table_2', 'table3'], 'table4', 'SvcDetordenes' ...]]],

    ]);

```

and it sorts the results returned from the association i specified to sort data.  
I know this is confusing if you have many associations , but its sorting my data how i wanted without any error in this moment
