# Simple query not working: how to debug? \[Solved\]

**URL:** https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265
**Category:** Need Help
**Created:** [May 8, 2018, 11:22am UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265 "2018-05-08T11:22:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)
#### Post date: [May 8, 2018, 11:22am UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265/1 "2018-05-08T11:22:44Z")

</div>

I’m on 2.6 CakePhp and I’d like to update field “stato” (an ENUM type field) on “customerbranches” table, and enter “closed” in it.

On VIEW I have this link:

```
echo $this->Form->postLink(__('Close'), 
         array( 'action' => 'close',
                     $customerbranch['Customerbranch']['id']),
                     array( 'confirm' => __('Sure?',))
             );

```

On CustomerbrachesController I have this, but it doesn’t update:

```
 public function close($id = null) {
       $this->Customerbranch->id = $id
           if ($this->Customerbranch->id) {
              $this->Customerbranch->saveField('stato', 'closed');
           }
 }

```

Any hint? Or how can I debug?

---

<div class="post-metadata">

### Author: ![MarksSoftwareGmbH](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/markssoftwaregmbh/32/1020_2.png) [@MarksSoftwareGmbH](https://discourse.cakephp.org/u/MarksSoftwareGmbH)
#### Post date: [May 9, 2018, 1:35pm UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265/2 "2018-05-09T13:35:55Z")

</div>

Hey @tom1884it,

I would get the entity first and the save the desired filed right away. Yes, you use the saveField method, but have you checked the saveField() method API Docs for your Cake version?

[https://book.cakephp.org/3.0/en/orm/saving-data.html#updating-data](https://book.cakephp.org/3.0/en/orm/saving-data.html#updating-data)

---

<div class="post-metadata">

### Author: ![MarksSoftwareGmbH](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/markssoftwaregmbh/32/1020_2.png) [@MarksSoftwareGmbH](https://discourse.cakephp.org/u/MarksSoftwareGmbH)
#### Post date: [May 9, 2018, 1:38pm UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265/3 "2018-05-09T13:38:20Z")

</div>

When you want to debug() your Cake App, just activate the

```
'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),

```

in the app.php and use debug($watzfoobar); in your Controller or Model or whereever you need it.

✌

---

<div class="post-metadata">

### Author: ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)
#### Post date: [May 10, 2018, 6:19am UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265/4 "2018-05-10T06:19:40Z")

</div>

Thank you for your support.  
'Cause I already knew the $id, I thought to directly update field “stato” of that id row.  
It seems I’m on Cake 2.6v.

Which “update” function can I use, sure it can work on any Cake version, instead of “saveField”? (even if I tried almost everything and I think it’s something not working…)

---

<div class="post-metadata">

### Author: ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)
#### Post date: [May 11, 2018, 10:47pm UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265/5 "2018-05-11T22:47:51Z")

</div>

I tried to put only a redirect inside the function and it is not working:

```
    public function close($id = null) { return $this->redirect(array('controller'=>'customers', 'action' => 'index')); }

```

What is wrong?! It’s seems like it totally ignore the postlink… even if it’s similar to a working “Delete” Form-postlink.

Please, I’m going crazy…

---

<div class="post-metadata">

### Author: ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)
#### Post date: [May 14, 2018, 11:54am UTC](https://discourse.cakephp.org/t/simple-query-not-working-how-to-debug-solved/4265/6 "2018-05-14T11:54:13Z")

</div>

Just got it. In the “head” of controller there was this line:

`$this-\>Auth-\>allow(‘subscription’, ‘paymentresponse’, ‘contractuploadreminder’, ‘stripe’);

I had to add my new function in the list, even if I don’t know if I have to protect it more.
